[Edu-sig] More on RPN example

Gordon Worley redbird@rbisland.cx
Fri, 28 Apr 2000 23:12:39 -0400


At 5:59 PM -0700 4/27/2000, Kirby Urner wrote:
>  >At the moment there is not documentation, which will hopefully be
>>forthcomming, but the text-based python program (thus cross platform)
>>does have some online help will get one started.  Also, more advanced
>
>I use IDLE.  I downloaded your modules.  I can import them, but
>what to do next?  Seems it'd take about 60 seconds to write a
>few lines showing a sample interaction in
>
>>>>  user types
>computer replies
>>>>  user types
>computer replies
>
>format. Maybe post that here and do a link from your web page
>to the edu-sig archives.

Well, taking 60 seconds seems a bit much to load and perform a single 
operation (on my computer and the Windows boxen at school the program 
has run practically instantaniously).  Instructions; hmm, let's see. 
Start by running rb_rpn.py (or just call it's main() function); this 
starts the current text based interface (I'm on a Mac and Tk support 
isn't that great, so I wanted a text-based interface first so that 
anyone can participate and I could do development (if someone would 
like to develop a Tk calculator interface, I'd be more than willing 
to accept the submition or help one in using my modules to create 
said calculator)).  I think that the online help (reached by typing 
'?' when at the main propmt) is pretty clear as to how each mode 
works, but I'll provide some examples anyway.  Before doing that, 
though, here are the available operators:

+ add x and y registers
- subtract x from y
* multiply x and y
/ divide y by x
% modulo y by x
^ raise y to the x power

doubling above opperators (++, %%, etc.) will cause operation to 
affect all registers

-> roll registers x through t up
<- roll registers x through t down
a-> roll entire stack up
a<- roll entire stack down
<> flip x and y resiters

pop pop stack
popall empty the stack
lastx get the last x value (does not work in interactive mode)

The three modes work like this:

interactive:
i: [enter numbers here]
i: [enter more numbers or do operations]
...keep doing this forever, if one'd like

static:
stack: [enter values to be put in stack, bottom to top, seperated by spaces]
opperators: [enter operators, seperated by spaces]
...these cycle back and force, returning results on the second, until 
the mode is left

expression:
exp: [enter RPN expression as it would be written on paper (i.e. 4 5 
+ 3 -), seperating each number or operator with spaces]

And that's it.  I hope that gets those of you interested started. 
I'll be included this documentation with a new release of the scripts 
that I should be making tonight or sometime over the weekend, and 
that should hopefully get you started.  Also, I'm not an IDLE user 
(doesn't run on the Mac) and thus don't know how it works, but you 
may find it easier to run these scripts from the interperter 
directly, if IDLE is anything like IDE on the Mac when asking for 
user input.

>That'd be a big help.  To expect such minimal documentation is
>not unreasonable, and really shouldn't take more than a few
>minutes of your time.

Well, if a few means ten, then I guess this documentation qualifies. 
In case anyone didn't see the first post, here is the address for 
where to download the scripts: 
<http://www.rbisland.cx/brew.html#scripts>.

Oh, and just incase this produces problems, the files may be using 
carrage returns at the end of each line rather than what one's OS 
expects depending on how one's version of tar is configured.



-- 
- Gordon Worley
http://www.rbisland.cx/
mailto:redbird@rbisland.cx