Post Reply 
No way to get an element free of brackets
02-21-2021, 05:27 AM
Post: #9
RE: No way to get an element free of brackets
(02-17-2021 06:26 PM)essen Wrote:  
(02-17-2021 05:02 PM)Albert Chan Wrote:  FYI, assignment via expr() might assign to local variable instead, if it exist.

EXPORT test()
BEGIN
local a := 123;
expr("a := 456");
return a;
end;

CAS> test()
456
CAS> a
a

Compared to Python, which can easily assign global variables.
(OTTH, this might not be a good thing ...)

>>> def test(): a = 123; globals()['a'] = 456; return a
...
>>> test()
123
>>> a
456

----------------------

My gold was to store numerical values enclosed in list by variables enclosed in list.
Especially when the variables are unknown in memory ahead. Until now I thought it impossible to do this without declaring each variable ahead in the program. Now possible doing what I want, my gold has been fulfilled. There's a lot of Input in solving cad. And would be very time consuming storing every single input the way you show this time. Still nothing compares to William Wickes
RPL HP48GX, HP50 programming tool in this sort of work. And it's a sad behavior excluding this programming tool from the Prime. With the faster running of Prime, it should be there. The only thing that could be better was the lack of symbolic in vector and matrix calculations. Fortunately, these calculations could be done in lists.

essen

I think you may want to read up a bit more on indirection. For example, when you have the following lists (in the CAS view, as it is much more complex in Home view):
Code:
list1:={1.2,2.3,3.4};
list2:={var1, var2, var3};
And you wish to programmatically do something like var1:=1.2; it is not simply a matter of typing
Code:
list2(1):=list1(1);
Consider the statement above from the point of view of someone trying to parse what you wrote. Do you intend replace the first element of list2? Or, knowing a priori that list2 contains a list of variables, should list2(1) be evaluated first to obtain the variable 'var1' and then this variable be used? In other words, should evaluation occur before storing, or should the left hand side be parsed as is? And how is a reader -- or the HP Prime in this case -- supposed to know your intent?

To get around this, you need to use indirect access and use the EXPR() command or the CAS equivalent: CAS().

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: No way to get an element free of brackets - Han - 02-21-2021 05:27 AM



User(s) browsing this thread: 1 Guest(s)