RPNlike STO/RCL on RPL calculator Message #1 Posted by David Hayden on 13 Nov 2009, 10:07 p.m.
One thing I missed when moving from a 41CV to a 50G was the ease of storing and recalling variables. To store 123 in register 01 on the 41CV you just type "123 STO 01" (6 keystrokes). You can even use the top two rows of keys as shortcuts for registers 0110 so the keystroke count is really 5 (1 2 3 STO SIGMA+). On the 50G, the variables are named and they have to be quoted, so the same thing would be something like 1 2 3 ' alpha R 0 1 STO  a whopping 9 keys.
Now it's true that once you've defined a variable, it's accessible from the VAR menu with one key to recall it and 2 keys to store into it (LS followed by the key for the variable), but if you aren't actually IN the VAR menu, then you add 3 keystrokes to get to the VAR menu and back (VAR to get there, LS (hold) PREV to get back).
To get around this, I created the following UserRPL programs STOn and RCLn. If you type "123 1 STOn" then it stores 123 into variable R1. Similarly "1 RCLn" will recall variable R1. If you type "123 'myvar' STOn" then it behaves just like STO, storing 123 in 'myvar'.
More specifically, STOn/RCLn examine the value on level 1 of the stack. If it's a positive integer or a real number greater than zero with no fractional part, then STOn/RCLn will store/recall the variable Rn where "n" is the value on level 1. If there are fewer than 2 values on the stack or if the conditions above aren't met, then STOn/RCLn just call STO/RCL.
With this behavior, you can assign the programs to the STO and RCL keys and your calculator will behave the way I want it to... :)
Here are the programs:
«
@ STOn/RCLn RPNlike STO and RCL functions
@ If the stack depth is 2 or more
@ and level 1 is a positive integer or real
@ with no fractional part, then store
@ level 2 in variable Rn where "n" is the
@ integer on level 1. Pop 2 levels
@
@ If the conditions aren't as mentioned above, then
@ call STO. Clike pseudo code is:
@ if (depth > 1 &&
@ (type == 0. && fractionalPart == 0 && value >= 0
@ type == 028&& value >= 0) {
@ construct string "Rn";
@ convert it to an identifier
@ store it.
@ } else {
@ STO
@ }
@ The pseudo code relies on C's shortcircuit
@ "and" operation. I'll do shortcircuit AND
@ like this (for 'A == 0 && B == 1"):
@ A 0 ==
@ IF DUP THEN
@ B 1 == AND
@ END
DEPTH 1 >
IF DUP THEN
OVER TYPE 0. == @ Is it REAL?
IF DUP THEN
3. PICK FP 0. == AND
3. PICK 0. Š AND
END
IF DUP NOT THEN
DROP
OVER TYPE 28. ==
IF DUP THEN
3. PICK 0 Š AND
END
END
END
AND
IF THEN
RŤI ŤSTR
"'R" SWAP + "'" +
OBJŤ
END
STO
»
'STOn' STO
@ Here is RCLn
«
DEPTH 0. >
IF DUP THEN
OVER TYPE 0. == @ Is it REAL?
IF DUP THEN
3. PICK FP 0. == AND
3. PICK 0. Š AND
END
IF DUP NOT THEN
DROP
OVER TYPE 28. ==
IF DUP THEN
3. PICK 0 Š AND
END
END
END
AND
IF THEN
RŤI ŤSTR
"'R" SWAP + "'" +
OBJŤ
END
RCL
»
'RCLn' STO
