The Museum of HP Calculators

HP Forum Archive 15

 What's the difference? (RPN/RPL)Message #1 Posted by Han on 22 Feb 2006, 1:43 a.m. Hm.. I've only used the HP48(S/SX/G/GX/G+), so bear with me. But what exactly are the differenced between RPN and RPL?

 Re: What's the difference? (RPN/RPL)Message #2 Posted by Andreas Terzis on 22 Feb 2006, 2:16 a.m.,in response to message #1 by Han Han, If you only have calculators of the HP-48 series then fairly you don't know the difference between RPN and RPL. RPN (Reverse Polish Notation) was used by earlier calculators up to the HP-18C or the HP-28C. RPL (Reverse Polish Lisp) is used in your calculator. One of their main differences is that RPN uses a four-level stack with a fifth element being the LastX number used for intermediate calculations, when RPL uses a stack that has an depth that is dictated by memory only; in other words you can store multiple elements in the stack, limited only by the available memory, and use them for calculations. Another difference is that RPN doesn't use a completely postfix notation - where you put the numbers in your stack first and then you perform the calculations (2 ENTER 5 +). In a lot of instances you use a prefix notation for functions, e.g. 7 STO 00, where you store the number 7 in register 00. In RPL you would store everything to the stack first and then perform operations on those objects, so the STO command would appear last. It is kind of a strict postfix notation language. For more on this, you can check some excellent literature on the HP Museum like: I hope I summarized some of the differences correctly for you here. Andreas Edited: 22 Feb 2006, 2:17 a.m.

 Re: What's the difference? (RPN/RPL)Message #3 Posted by Garth Wilson on 22 Feb 2006, 3:10 a.m.,in response to message #2 by Andreas Terzis As one who has never used or paid much attention to RPL myself, perhaps I can ask further, for the original poster. I understand RPL has strict program structures with no GOTO and, I assume, no labels either; and further, that an RPL program is compiled from text source code instead of being keyed directly in like you would do on an RPN programmable calc. I expect that variables can have names, and that you can probably make different kinds of variables, arrays, and data structures. Is this all correct? Does it compile "words" into a dictionary like Forth does? Perhaps these will bring to mind other things about it to describe briefly as well.

 Re: What's the difference? (RPN/RPL)Message #4 Posted by Marcus von Cube, Germany on 22 Feb 2006, 3:20 a.m.,in response to message #3 by Garth Wilson Quote: Does it compile "words" into a dictionary like Forth does? An RPL program is an object that can reside on the stack or in a named variable. Once there, it can be 'evaluated'. Evaluating a variable is performed by just using its name. In that sense, an RPL program stored in a variable becomes part of the language. I guess that's very similar to Forth. Marcus

 Re: What's the difference? (RPN/RPL)Message #5 Posted by Geir Isene on 22 Feb 2006, 6:31 a.m.,in response to message #4 by Marcus von Cube, Germany Quote: I guess that's very similar to Forth. Except the interactivity of the Forth environment is lost (which IMHO is one of the beauties of Forth and is one of the reasons why RPL is indeed inferior to Forth.)

 Re: What's the difference? (RPN/RPL)Message #7 Posted by Eddie Shore on 26 Feb 2006, 11:23 a.m.,in response to message #6 by James M. Prange (Michigan) It does take some getting use to without having LBL and GTO commands to work with. The << sub program >> 'TEMPVAR' STO then TEMPVAR EVAL works.

 Re: What's the difference? (RPN/RPL)Message #8 Posted by James M. Prange (Michigan) on 27 Feb 2006, 5:10 p.m.,in response to message #7 by Eddie Shore Quote: It does take some getting use to without having LBL and GTO commands to work with. Okay, I accept that for someone who's always had these available, learning to work without them may very well be difficult to get used to. Quote: The << sub program >> 'TEMPVAR' STO then TEMPVAR EVAL works. Using subprograms in RPL is more like using GOSUBs in other languages, or in the case of named subprograms, rather like a CALL in some other languages. More likely substitutes for GOTOs would be conditional and looping program structures. Unless a local variable named 'TEMPVAR' already exists, ```<< sub program >> 'TEMPVAR' STO ``` makes a global variable. This makes sense if the intent is to make a utility program that will be called by various other programs, but isn't so good if the intent is to make a subprogram to be used more than once in a single program. For one thing, resolving a global name generally takes longer than resolving a local name or leaving the subprogram on the stack and using stack manipulation commands, and probably more importantly, the global variable will overwrite any global variable named 'TEMPVAR' in the current directory, and will be stored in the current directory until the user purges it. With the subprogram stored in a global variable, executing its unquoted name, TEMPVAR, evaluates whatever's stored in the variable, so the EVAL is probably unneeded, although that depends on what evaluating << sub program >> returns. We could do something like: ```<< @ Begin program. << subprogram >> @ Place the subprogram on the stack. 'TEMPVAR' @ Place the name on the stack. STO @ Store them as a global variable. ... @ Do some stuff. TEMPVAR @ Evaluate subprogram. ... @ Do some more stuff. TEMPVAR @ Evaluate subprogram. ... @ Do yet more stuff. TEMPVAR @ Evaluate subprogram. 'TEMPVAR' @ Place the name on the stack. PURGE @ Discard the global variable. ... @ Finish up. >> @ End program. ``` But that leaves the possibility of inadvertently purging an already existing variable named 'TEMPVAR', and of course it assumes that the program doesn't change directories. We could make a utility program using argument checking and the SysRPL CREATE command as a variation on the UserRPL STO command. Given any object on level 2 and a global name on level 1, CREATE creates a new global variable at the beginning of the current directory, even if a same-named variable already exists in the directory. This would have the advantage of not overwriting anything, and since it would be at the beginning of the current directory, it would be resolved quickly. Of course, this assumes that the program doesn't change directories. As long as the variable exists, any same-named variable in the directory will be inaccessible. The variable will still be stored until the user purges it. For a subprogram, I suggest using a local variable structure instead, such as: ```<< @ Begin program. << subprogram >> @ Place the subprogram on the stack. -> p @ Bind it in a local variable. << @ Begin the defining procedure. ... @ Do some stuff. p @ Place the subprogram on the stack. EVAL @ Evaluate subprogram. ... @ Do some more stuff. p @ Place the subprogram on the stack. EVAL @ Evaluate subprogram. ... @ Do yet more stuff. p @ Place the subprogram on the stack. EVAL @ Evaluate subprogram. ... @ Finish up. >> @ Abandon the local variable. >> @ End program. ``` Of course, while a local variable named 'p' exists, nothing else named 'p' is accessible. Using the local variable has the advantage that creating it won't overwrite any already existing variable, and that it will be automatically discarded when its defining procedure ends. Another approach is to leave the subprogram on the stack and use the stack manipulation commands, such as the following: ```<< @ Begin program. << subprogram >> @ Place the subprogram on the stack. ... @ Do some stuff. a PICK @ Copy subprogram from level a to level 1. EVAL @ Evaluate subprogram. ... @ Do some more stuff. b PICK @ Copy subprogram from level b to level 1. EVAL @ Evaluate subprogram. ... @ Do yet more stuff. c ROLL @ Move subprogram from level c to level 1. EVAL @ Evaluate subprogram. ... @ Finish up. >> @ End program. ``` In the above, a PICK or b PICK could be some other command in the PICK family, such as DUP, OVER, or (in the 49 series) PICK3, and c ROLL could be some other command in the ROLL family, such as SWAP or ROT. This approach may well be a bit faster and/or smaller, but requires the user to keep track of which level the subprogram is in. Regards,James

 Resourceful-Proficient-Natural vs. Re-Pe-Lent :-)Message #9 Posted by Valentin Albillo on 22 Feb 2006, 11:28 a.m.,in response to message #1 by Han Best regards from V.

 Literature suggestions (was: What's the difference? (RPN/RPL))Message #10 Posted by Vieira, Luiz C. (Brazil) on 23 Feb 2006, 2:48 a.m.,in response to message #1 by Han Hi Han, all; Bill Wickes' `HP41/HP48 Transitions` is one of the most concise sources of information for this very subject. Also, the single-volume version of the HP48 Owner's Manual (mine is January 1993 print, Edition 3) has an additional appendix comparing the HP48S/SX and the HP41. Sometime ago I digitized and converted it to a typeset PDF, available through this link. It's worth reading, only seven pages long. Cheers. Luiz (Brazil) Edited: 23 Feb 2006, 2:49 a.m.

 Re: Literature suggestions (was: What's the difference? (RPN/RPL))Message #11 Posted by James M. Prange (Michigan) on 23 Feb 2006, 10:01 p.m.,in response to message #10 by Vieira, Luiz C. (Brazil) Quote: Bill Wickes' `HP41/HP48 Transitions` is one of the most concise sources of information for this very subject. Note that this book, along with his Insights books for the 28 and 48 series, is available on the Museum CD set / DVD. See: http://www.hpmuseum.org/cd/cddesc.htm. Regards,James

 Re: Literature suggestions (was: What's the difference? (RPN/RPL))Message #12 Posted by Han on 23 Feb 2006, 10:25 p.m.,in response to message #11 by James M. Prange (Michigan) Luiz and James, Thanks for the links to the information! Han

Go back to the main exhibit hall