by mschaef · 7y ago · 0 comments
Try entering this and storing it into a variable:
<< -> x << << x >> >> >>
If you run that object with something on the stack, you'll get this in return. 1: << x >>
That x is a local variable reference, which makes it different than if you just entered this << x >>
And if you evaluate it, it blows up with an error to that effect. (Since RPL doesn't really close over the lexical environment.)Years ago, I wrote a Scheme-based derivative of RPL that fixed some of this and found it rather fun to play around with.
Min has lexical scoping too.
I have a stopwatch function in my HP48 that I don't want using a local variable (avoid polluting my precious menu), or having to keep it in a stack.
Instead I want the value of the last time I ran the program to be stored within the program itself. I believe this is called a closure in CS.
Right now I can have << value -> X 'expression' EVAL rest of the program >>
And it'll work just fine, but how could I get the value at the very top modified?
(I know my cell phone has a stopwatch. We're not allowed phones at work)
Not at all.
> I have a stopwatch function in my HP48 that I don't want using a local variable (avoid polluting my precious menu), or having to keep it in a stack.
The first thing that comes to mind is that there's a hidden directory at the root that the ROM itself uses to store stuff like this. This link talks a bit about how to get there:
https://www.hpmuseum.org/forum/thread-12986.html
This uses SYSEVAL to call into a normally-not-visible object that puts the name of the directory on the stack. From there, you should be able to read/write the variable.
You may also be able to do some hacky stuff with self-modifying code, but that's honestly something I'd avoid unless you want to try it for fun.