Post Reply 
No way to get an element free of brackets
02-13-2021, 09:58 AM
Post: #1
No way to get an element free of brackets
Using SUB to extract an element from a list just render the element still being
enclosed in list brackets. Seems being no command to get the element free of
the brackets. Using "Get" does not work either. This lack of command makes it
impossible to store a list of values in variables contained in a list. For example:
Doing a "For loop" on 2 lists containing values and the variables to store the values in, cannot be done.

lst1:={1,2,3}, lst2:={'myv1', 'myv2', 'myv3'};

For i1 FROM 1 TO si DO
lst2(i1):=lst1(i1);
END;

Any rounds in this loop will just produce {1}:={'myv1'}, {2}:={'myv2'}, ...
and so on. You cannot get off the brackets.

This is a serious drawback, and render programming with the Prime an impossible
task.
Find all posts by this user
Quote this message in a reply
02-13-2021, 05:38 PM
Post: #2
RE: No way to get an element free of brackets
(02-13-2021 09:58 AM)essen Wrote:  lst2(i1):=lst1(i1);

I am not sure the question is, but above can be confused with function definition.

Perhaps you meant lst2[i1] := lst1[i1] ?

Or, if you really wanted to assign global variables to values (why ?)

CAS> lst1 := {1, 2, 3}
CAS> lst2 := {"myv1", "myv2", "myv3"}
CAS> FOR i1 FROM 1 TO 3 DO expr(lst2[i1] + ":=" + lst1[i1]); END;

CAS> myv1, myv2, myv3       → [1, 2, 3]
Find all posts by this user
Quote this message in a reply
02-13-2021, 05:49 PM
Post: #3
RE: No way to get an element free of brackets
try this short program:

#cas
GET(r,u):=
BEGIN
RETURN r(u);
END;
#end

GET({3,7,8},1) --> 3

GET({3,7,8},2) --> 7

GET({3,7,8},3) --> 8[/php]
Find all posts by this user
Quote this message in a reply
02-14-2021, 03:45 PM (This post was last modified: 02-15-2021 08:01 AM by essen.)
Post: #4
RE: No way to get an element free of brackets
(02-13-2021 05:38 PM)Albert Chan Wrote:  
(02-13-2021 09:58 AM)essen Wrote:  lst2(i1):=lst1(i1);

I am not sure the question is, but above can be confused with function definition.

Perhaps you meant lst2[i1] := lst1[i1] ?

Or, if you really wanted to assign global variables to values (why ?)

CAS> lst1 := {1, 2, 3}
CAS> lst2 := {"myv1", "myv2", "myv3"}
CAS> FOR i1 FROM 1 TO 3 DO expr(lst2[i1] + ":=" + lst1[i1]); END;

CAS> myv1, myv2, myv3       → [1, 2, 3]
-----------------------------------------------

Your method now works.
I up-grated in the evening to ver. 2.1.14425 (2020 01 16)
It rather likely I had a programming error that has been corrected
along the way without knowing this possibly could be responsible, but
not the Prime version. Don't know for sure.

//LSTOR({−59.0955172399,−25.2673105008,−31.5033804435,39.3,−4.5,9.5},{"ɷ2","ɷ1","y2","x2","y0","x0"})
#cas
n:=0;
LSTOR(l1,l2):=
BEGIN
LOCAL i1:=1,si;
ls1:=l1;
ls2:=l2;
si:=length(ls2);
FOR i1 FROM 1 TO si DO
expr(""+ls2[i1]+":="+ls1[i1]);
END;
IF (i1==si+1) THEN n:=1;
END;
END;
#end

This cryptic way to strip the brackets in lack of a dedicated
stripping command gets me saying; We still needs a dedicated
stripping command to do this. The problem exist with a Vector list too. And still, none of these works:
get({1,2,3},2) or sub({1,2,3},1,2). Neither in Home using GET and SUB. The subtracted element using the sub in cas or SUB in HOME are just placed enclosed in list brackets. The get or GET does nothing.

I would like seeing a method for this.
But, Thank you for your method.

essen
Find all posts by this user
Quote this message in a reply
02-17-2021, 10:48 AM (This post was last modified: 02-17-2021 10:56 AM by Didier Lachieze.)
Post: #5
RE: No way to get an element free of brackets
Here is a simplified way to use lists to assign values to global variables, not requiring CAS:

Code:
EXPORT myv1, myv2, myv3;

EXPORT LSTOR(l1,l2)
BEGIN
 EXPR(l2+":="+l1);
END;

EXPORT TST()
BEGIN
 LOCAL lstv;
 lstv:={"myv1", "myv2", "myv3"};
 LSTOR({1,2,3},lstv);
 PRINT(myv1+" "+myv2+" "+myv3);
 LSTOR({4,5,6},lstv);
 PRINT(myv1+" "+myv2+" "+myv3);
END;
Find all posts by this user
Quote this message in a reply
02-17-2021, 05:02 PM
Post: #6
RE: No way to get an element free of brackets
(02-17-2021 10:48 AM)Didier Lachieze Wrote:  Here is a simplified way to use lists to assign values to global variables, not requiring CAS ...

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
Find all posts by this user
Quote this message in a reply
02-17-2021, 05:52 PM
Post: #7
RE: No way to get an element free of brackets
(02-17-2021 10:48 AM)Didier Lachieze Wrote:  Here is a simplified way to use lists to assign values to global variables, not requiring CAS:

Code:
EXPORT myv1, myv2, myv3;

EXPORT LSTOR(l1,l2)
BEGIN
 EXPR(l2+":="+l1);
END;

EXPORT TST()
BEGIN
 LOCAL lstv;
 lstv:={"myv1", "myv2", "myv3"};
 LSTOR({1,2,3},lstv);
 PRINT(myv1+" "+myv2+" "+myv3);
 LSTOR({4,5,6},lstv);
 PRINT(myv1+" "+myv2+" "+myv3);
END;

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

I tried it out.

It works only when these variables has been defined ahead in user memory.
You did define them ahead with the EXPORT before running. Yours also
works having this expression, EXPR({"myv1","myv2"}+":="+{1,2}),
in the Primes input window, when the variables has been defined ahead.
Otherwise, not defined ahead it errors.
With the calculator in cas mode and same, or as, expr({"myv1","myv2"}+":="+{1,2}), it won't work, even with variables defined ahead.

With the code I posted running this, LSTOR({1,2},{"myv1","myv2"}),
it works without having the variables defined ahead. That was my gold.

But your method can be used instead of this FOR LOOP in my cas
LSTOR program. This makes it a bit easier.

Some inconsistency are observed.

Thank you

essen
Find all posts by this user
Quote this message in a reply
02-17-2021, 06:26 PM
Post: #8
RE: No way to get an element free of brackets
(02-17-2021 05:02 PM)Albert Chan Wrote:  
(02-17-2021 10:48 AM)Didier Lachieze Wrote:  Here is a simplified way to use lists to assign values to global variables, not requiring CAS ...

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
Find all posts by this user
Quote this message in a reply
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
02-21-2021, 07:36 AM
Post: #10
RE: No way to get an element free of brackets
(02-21-2021 05:27 AM)Han Wrote:  
(02-17-2021 06:26 PM)essen Wrote:  ----------------------

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().

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

"You may want to read up on indirection".
Find all posts by this user
Quote this message in a reply
02-24-2021, 10:11 AM
Post: #11
RE: No way to get an element free of brackets
(02-21-2021 05:27 AM)Han Wrote:  
(02-17-2021 06:26 PM)essen Wrote:  ----------------------

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().

For Han and Albert.:

Sorry, my bad !

Well; I looked it up in a dictionary as not knowing the word, and
could not afterwards se any other meaning as used in Alberts text.

In my dictionary it stands like this:

indirection [indi'recSen] sb uaerlighed, svigfuldhed, kneb, fif.
These four words stands for;
dishonesty, deceitfulness, trick, dodge.

This created a meaning - a wrong one - unfortunately.
This dictionary are dated 1977. Could be the reason. Or this english
word just means other in us.

My excuse doesn't mean that I' m fishing for yours and Alberts
forgiveness. I am not. It just means I want to be honest telling how
this happend. I am not yet staying here.

By the way - concerning the answer to my Prime enquiry;
This is all there are too it: {48}[1]
Doing this in the command line places 48 on the stack without brackets.
Coming from HP48, this simple instruction was not just apparent to me.
Old fars on this forum could be expected to know it and posted this answer.

I tried to delete my account, as earlier said, I' m out from here. I am ready
to start translating HP48 programs to Prime. Already done a few ones

Kind regards
essen
Find all posts by this user
Quote this message in a reply
Post Reply 




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