HP Forums
Why x:=CAS("x") = 0 ? - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Why x:=CAS("x") = 0 ? (/thread-10395.html)

Why x:=CAS("x") = 0 ? - Carlos295pz - 03-27-2018 12:52 PM

I know that doing this may not make much sense, since the use of CAS variables does not require the creation of an HP PPL variable with the same name, or even that they are created. But recently I could see how some people use it and I have doubts.

LOCAL x=CAS("x");
PRINT(x) → 0 //Why? recursivity?

LOCAL var1=CAS("x");
PRINT(var1) → x //Expected, usual practice

LOCAL x=CAS(CAS("x"));
PRINT(x) → x //Why???

I would like to know what this is due to and if there will be any correction in this regard.

RE: Why x:=CAS("x") = 0 ? - Han - 03-27-2018 02:24 PM

When using CAS(), any variable references will first be resolved within the user's existing CAS environment. Then, variables are resolved using the local variables from the routine that called CAS(). At that instance, the local variable x has a default value of 0. You can test this by separating the declaration from the assignment.

When you use CAS(CAS()) the inner CAS() commands will try to use the outer CAS() command's local variables (and there are none).

RE: Why x:=CAS("x") = 0 ? - Carlos295pz - 03-28-2018 02:47 AM

It is an assignment in the same line of LOCAL, I would understand it if it were:
But this could also be possible:
LOCAL var1:=var1; → var1=0 ??

I do not really agree that it fails like that.

Regarding the double environment generated by CAS CAS, it seems to me that it is not working as expected, now it can be exploited but will should continue searching until it leaves the final nested environment?

RE: Why x:=CAS("x") = 0 ? - Carlos295pz - 03-28-2018 03:21 AM

I'm considering name resolution, but something does not quite convince me.

RE: Why x:=CAS("x") = 0 ? - Carlos295pz - 03-29-2018 11:14 AM

Great Mr. parisse, I invoke you, please destroy me with their words.