50G Programming question



#7

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 <<E EVAL>> >>

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?


#8

-> 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.

#9

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


#10

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:)

#11

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!


#12

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


Possibly Related Threads...
Thread Author Replies Views Last Post
  HP-48GX & 50G Question Matt Agajanian 2 627 12-08-2013, 10:17 PM
Last Post: Matt Agajanian
  HP 50g - question about matrices arrays vectors etc. Sean Freeman 6 900 11-14-2013, 01:44 PM
Last Post: peacecalc
  HP 50g: question about bugs Miguel Toro 2 509 09-26-2013, 01:27 PM
Last Post: Miguel Toro
  HP 50G serial port programming Chris Smith 2 533 06-15-2013, 02:47 PM
Last Post: Chris Smith
  Simple? programming question [WP34S] Shawn Gibson 3 551 03-15-2013, 11:56 AM
Last Post: Didier Lachieze
  hp 50g Programming David Sgroi 4 586 01-17-2013, 03:58 PM
Last Post: David Hayden
  Help - 50G C programming BruceH 4 596 09-29-2012, 10:14 AM
Last Post: David Hayden
  WP-34S Programming Question Matt Agajanian 2 475 08-04-2012, 02:04 PM
Last Post: Matt Agajanian
  50G CASINFO & CASDIR Question Matt Agajanian 17 1,666 04-30-2012, 11:12 AM
Last Post: Software49g
  WP 34S programming question Nigel J Dowrick 35 2,709 04-10-2012, 02:23 AM
Last Post: Walter B

Forum Jump: