Post Reply 
Symbolic reference question
06-08-2020, 09:40 PM
Post: #1
Symbolic reference question
Within a program I have arrived at:

c:={a,b}
d:={100.5,102.5}

At the command entry line, I can enter {a,b}:={100.5,102.5}, after which:

a:=100.5
b:=102.5

What I would like to do is make the {a,b} = {100.5,102.5} assignment by using the variables c and d, instead. How can this be accomplished?

Something like: c:=d, or EXECON("&1:=&2",c,d), I'm having trouble accessing the contents of the variables appropriately.

Thanks!

-Dale-
Find all posts by this user
Quote this message in a reply
06-09-2020, 06:27 AM
Post: #2
RE: Symbolic reference question
Hello,

Sorry, appart from using execon, there is no other solution at the moment.

note that you should have c:={'a','b'} so that c contains {a,b}...

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
06-09-2020, 08:41 AM
Post: #3
RE: Symbolic reference question
In CAS you can also use: zip('sto',d,c)
Find all posts by this user
Quote this message in a reply
06-09-2020, 09:32 AM
Post: #4
RE: Symbolic reference question
Thank you, Cyrille.

Within the program I had used c:={'a','b'}, and that was how I was able to get to the point where c={a,b}.

However, I haven't been successful with: EXECON("&1:=&2",c,d);

Can you think of a syntax that works? I've tried several ways, with no success. This seems like such a basic operation. It's surprising that symbolic references, don't seem to be programmable, even though directly using the contents of the symbolic reference works.

Summary:
[CAS]
purge({a,b});
c:={'a','b'};
d:={100.5,102.5};

c:=d; // ==> c gets set to the contents of d, (as expected).
EXECON("&1:=&2",c,d); // Error message ...

{a,b}:={100.5,102.5}; // a=100.5; b=102.5 (Works. How to get to this result, using the symbolic reference?)
Find all posts by this user
Quote this message in a reply
06-09-2020, 10:17 AM
Post: #5
RE: Symbolic reference question
(06-09-2020 08:41 AM)Didier Lachieze Wrote:  In CAS you can also use: zip('sto',d,c)

It seems RPN-ish, but zip('sto',d,c) does work. Thank you very much for your help! Can you think of a way to make EXECON() accomplish the same thing?

-Dale-
Find all posts by this user
Quote this message in a reply
06-09-2020, 12:31 PM
Post: #6
RE: Symbolic reference question
(06-09-2020 10:17 AM)DrD Wrote:  Can you think of a way to make EXECON() accomplish the same thing?

No, and the reason could be that EXECON() is a HOME and not a CAS function and as such can't handle symbolic references. While zip() being a CAS function has symbolic support.
Find all posts by this user
Quote this message in a reply
06-09-2020, 01:29 PM
Post: #7
RE: Symbolic reference question
error is due to the := adding some form of " " may help;
i had similar problem; can not seem to remember the way a i used "" to solve this problem.

try
Step 1.
EXECON("""&1:=&2""",c,d);

Step 2.
EXPR(Step 1)
Find all posts by this user
Quote this message in a reply
06-10-2020, 05:49 AM
Post: #8
RE: Symbolic reference question
Hello,

execon does not work because execon adds () around each object to avoid user unexpected results...
things like L1:={1+i, 2+i}
execon("&*2", L1) would execute 1+i*2 and 2+i*2 (which is not what the user was expecting) if they were no guard () added...
in your case, you end up with (a):=(1) which will not work...

I am afraid that the solution here is an EXPR...
you might be able to do some variation of EXPR(MAKELIST(L1(I)+":=",I,1,SIZE(L1))+L2)

PPL is not a symbolic language, as such it is not designed to manipulate variables. variable content? yes, variables themselves as objects? not really.. is it impossible, obviously no, but it is not super easy either.

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
10-03-2020, 02:05 AM
Post: #9
RE: Symbolic reference question
I'd say the best solution would be to use a helper function:

Code:

dupe:= (expr_) -> id({expr_}, {expr_});
{c, {a, b}} := dupe(100.5,102.5);

the 'seq' function can also be used here

Code:

{c, {a, b}} := seq({100.5,102.5}, 2);

if you need a more generalized solution:

Code:

// https://en.wikipedia.org/wiki/Currying
brancher:= (times_) -> ((expr_)->seq({expr_}, times_));
{c, {a, b}} := brancher(2)(100.5,102.5);

// the dupe function can be rewritten as
dupe:= brancher(2);

Having functions be first class is a really powerful feature of CAS, please use it.
Find all posts by this user
Quote this message in a reply
Post Reply 




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