The Museum of HP Calculators

HP Forum Archive 18

 50G Programming questionMessage #1 Posted by Roger King on 8 Dec 2007, 8:26 p.m. 50G programming question about variables. I hope this makes sense. I am writing a program (User RPL) that takes a user supplied expression off the stack, say X*Y. Within the program I want to then evaluate this expression for various values of X and Y. So the question is: how do I actually evaluate the expression once it is inside the program. The ways I have been trying essentially involve defining local variables for X and Y, but this is not working. For example (The actual program I am working on is more complicated: it's for propagation of errors): << 3 4 -> E X Y <> >> will just give me the expression (E) back without evaluating it for X and Y. I am guessing this is an issue with the scope the local variables, but I am not seeing a way around this except to use global variables. Is there a way to accomplish the above program just using local variables?

 Re: 50G Programming questionMessage #2 Posted by reth on 9 Dec 2007, 1:30 a.m.,in response to message #1 by Roger King -> E X Y expects 3 elements in stack levels 3, 2 and 1 (in that order) << E EVAL >> errors cause you haven't assigned anything to E (assuming the stack was clear before you start your program); Edited: 9 Dec 2007, 1:31 a.m.

 Re: 50G Programming questionMessage #3 Posted by James M. Prange (Michigan) on 9 Dec 2007, 3:03 a.m.,in response to message #1 by Roger King Okay, I take it that you have an expression already that contains the names X and Y, such as 'X+Y', already on the stack. When you compiled (ENTERed) that expression, X and Y were compiled as global names. The easiest way around this is to start those two names with a left-arrow (character 142) in both the expression and the program, which tells the compiler to compile them to local names, even if there's no other reason for doing so. The only disadvantage is that each name will take an extra byte of memory. This works for the 48G series and higher. An alternative method (most useful on the 28 series and 48SX/S) and is to have the local names already existing. For example, you could run a program ```\<< 0 0 \-> X Y \<< HALT \>> \>> ``` Now the local variables X and Y exist in the suspended environment. Enter the expression containing the names X and Y, and they'll be compiled as local names. Now you can press CONT to finish the halted program, abandoning the local variables. The disadvantage is that you'll again have to force the existence of local variables X and Y if you decide to edit the expression. Regards,James

 Re: 50G Programming questionMessage #4 Posted by Roger King on 9 Dec 2007, 5:19 p.m.,in response to message #3 by James M. Prange (Michigan) Thanks, I was thinking that it was an issue with the local vs. global variables, but was not seeing a way around it. I am still new to user RPL, and I find it a very strange language. I also just found a way to get the program to work using the "where" function. << -> E << E {2 X 3 Y} | EVAL>> >> would evaluate an expression E (taken from the stack) for X=2 and Y=3. Ahh, its satisfying to find a couple of solutions after banging my head against the wall for a couple of days:)

 Re: 50G Programming questionMessage #5 Posted by Graham Gibbs on 11 Dec 2007, 6:12 a.m.,in response to message #3 by James M. Prange (Michigan) Hi James - I only discovered the wonder of HP calculators about 18 months ago. I've got an HP 50g and I love it!! (I've also got a 32SII and a 35s). I'm always very impressed by your depth of knowledge & understanding of RPL. Have you considered writing a book on User RPL? - I'll buy one!! Keep up the good work!

 Re: 50G Programming questionMessage #6 Posted by James M. Prange (Michigan) on 11 Dec 2007, 6:02 p.m.,in response to message #5 by Graham Gibbs Hi Graham, Thanks; it's always nice to read that someone finds my posts useful. Quote: Have you considered writing a book on User RPL? - I'll buy one!! The trouble with that idea is that almost all of the information that I write about UserRPL is already available, either in the documentation written by HP, or in Bill Wickes's (the "Father of RPL" and a very clear writer besides) Insights books, although (at least usually) re-written into "my own words". I suggest that anyone interested in gaining in-depth knowledge of UserRPL purchase the Museum's CD/DVD set (see: http://www.hpmuseum.org/cd/cddesc.htm), which has scans of all of Bill Wickes's books about RPL, and HP's documentation for at least the 28 series and the 48SX/S. For HP's 48G series and 49 series documentation (and much additional information), try some searches at http://www.hpcalc.org/. For those more comfortable with Classic RPN, it may be better to read Bill Wickes's HP 41/HP 48 Transitions (also available as a scan on the Museum's CD/DVD set) first. I do try to write clearly and be sure that what I write is technically correct, but I know that I have a strong tendency to be "wordy" and "ramble" into topics that have only a minor connection to what I'm trying to explain (and everything is somehow connected with everything else), so my writing is often not what I'd consider to be concise. UserRPL commands are written (mostly) in SysRPL, with some Saturn assembly language. SysRPL commands are written using other SysRPL commands or Saturn assembly language, and ultimately it all gets down to Saturn assembly language. A good deal of information on these can be found at http://www.hpcalc.org/. Also make it a habit to read the comp.sys.hp48 usenet group. In case you don't already use a news client, the newsgroup can also be accessed at http://groups.google.com/group/comp.sys.hp48/. Regards,James

Go back to the main exhibit hall