[Edu-sig] More on RPN example

Kirby Urner pdx4d@teleport.com
Sat, 29 Apr 2000 08:49:46 -0700


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

Gordon --

Thanks for the boost.  It was just that initial hurdle of 
knowing which module to import (I'd guess wrong), which 
made it seem difficult.

To be very detailed:  I created a subdirectory under 
Python called \rpn into which I unzipped your py files.
Then I went:

>>> import sys
>>> sys.path.append(".\\rpn")
>>> import rb_rpn

That last command automatically triggered main() -- main()
being the last line in the module -- and got me your prompt.
The following is the first several lines of my session (I
also explored other modes of course):

Red Bird's RPN 0.4.1

Type i for interactive mode, s for static mode, e for 
expression mode, ? for help, or q to quit or leave mode 
(when in one).
:e
expression mode
exp:4 3 +
[4.0]
[3.0, 4.0]
[3.0, 4.0]
4 3 +
[7.0]
exp:4 5 * 2 +
[4.0]
[5.0, 4.0]
[5.0, 4.0]
4 5 *
[20.0]
[2.0, 20.0]
[2.0, 20.0]
20 2 +
[22.0]

As you can see, the program runs just fine in IDLE, which is 
just like the standard interpreted environment except color
coded (computer output text in blue, my entered expressions
in black).  In the Windows environment, it's a choice between
IDLE and a DOS box.  As I've posted to edu-sig before, I see
no real advantages to using DOS box Python for any purpose
(unless that's all you've got) as IDLE gives the exact same 
experience (of using Python interactively), just in a much 
friendlier environment.

As for Tk, I think the obvious thing, which might be fun
to do, would be to wrap a simple RPN calculator interface
around your modules.  I always prefered Hewlett-Packards
RPN calculators to TI's parentheses-infested ones.  You
have an Enter key to push a value on the stack, which
is 4 levels deep.  Even had a roll key for rolling 
values around.

E.g.  3 [enter] 4 +  gets you 7 (in bottom stack
position).  

After you hit [enter] the first time, 3 is in the "y" 
position on the stack (2nd level), with a copy in "x" 
i.e.:

3        [enter]   4       +
       
Stack  
a:        a:       a:      a:
z:        z:       z:      z:
y:        y: 3     y: 3    y: ?
x: 3      x: 3     x: 4    x: 7  <-------- visible

What I'm forgetting (hence the question mark) is if 
the 3 stays in the y: position, so that repeated 
pressing of the + key gets you 10, 13, 16... (don't
have a Hewlett-Packard around to test).

Anyway, the important point is that the bottom of
the stack is likewise what's displayed on the 
calculator.

With tkinter (the Python wrapper to Tk), you'd just
make some buttons in a frame, and have a read-only
display box.  If I were doing this, I'd add a 
prominent Enter key and basically emulate HP's
most excellent design.

GUI RPN calculators are already out there -- 
this wouldn't be the first or necessarily the
fanciest.  But it'd be a good example of how to
use Tk with Python.  A fun project.  

Conway's Game of Life is another one I'm thinking 
about doing (probably won't have time for either -- 
wouldn't be surprised if the latter had already
been done (which doesn't mean I wouldn't do it 
again, as the point is learning, not being the 
one and only to have ever done something)).

Kirby

PS:  my Python version of the Sieve of Erasthosthenes
(another classic thing to do in any computer language) 
is now linked from the Prime Pages.  See:
http://www.utm.edu/research/primes/programs/Eratosthenes/