Re: UserRPL local variables not available to algebraics? Message #18 Posted by cyrille de brebisson on 29 Mar 2012, 6:56 a.m., in response to message #1 by John R. Graham
Quote:
I don't usually do algebraic notation, so maybe I'm missing a nuance here. I was helping my college age son write a program where he wanted to evaluate an algebraic expression stored in a global variable against stack supplied variables. Simple, I thought. Just define local variables that match variables in the algebraic. However, local variables don't appear to be available to an algebraic. I can store the named variables in globals with STO and the algebraic can access them, but not if they're local.
hello
yes, but what you need to understand is that when an object is compiled (when you press ENTER on something), names will be compiled as local variables ONLY if the local exists at that time...
so, doing: 'A+B' 'C' STO followed by calling C EVAL in a program when A and/or B are local variable will cause A+B to still refer to the GLOBAL variables as local A/B did not exist at that point...
also, doing:
2 'A' STO << 0 -> A << 'A' 1 -> A << EVAL >> >> will return 1 because when 'A' was compiled, a local variable A DID exist and 'A' will evaluate a local, in this case the A containing 1...
doing:
2 'A' STO << 0 -> A << 'A' 1 -> A << >> >> EVAL will err as there is no more local A when 'A' is evaluated...
cyrille
|