HP Forums

Full Version: Symbolic reference question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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-
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
In CAS you can also use: zip('sto',d,c)
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?)
(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-
(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.
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)
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
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.
Reference URL's