Post Reply 
Walkthrough of an RPL program for an RPN programmer
08-26-2018, 03:37 AM
Post: #21
RE: Walkthrough of an RPL program for an RPN programmer
(08-25-2018 01:35 PM)Maximilian Hohmann Wrote:  Thanks for that great thread!

You're welcome!

RPN vs. RPL

RPN: Reverse Polish Notation
RPL: Reverse Polish Lisp

Some prefer postfix notation to using RPN. In the end it's used in multiple languages and contexts. Forth and RPL use RPN as well.
In this forum RPN is often used as the language of the classic HP calculators which I consider unfortunate.

For the user of the HP-19BII it's irrelevant whether the code was written in Saturn assembler or System RPL or whatever. As far as I know RPL as a programming environment is not exposed to the user. However you can write sophisticated programs using the solver.

I'm not familiar with that calculator. Thus I don't know the details related to the entry system. It appears to be similar to the classic models.



Quote:The best example for that is the expression « → a 'a+a' » of which, even after having read the whole thread, I still don't have the faintest idea what it might do.

It takes the top level element of the stack, assigns it to the local variable \(a\) and evaluates the algebraic expression \(a+a\).
In other words: it doubles the top level element.

All of these programs do the same thing:
Code:
« DUP + »

Code:
« → a « a DUP + » »

Code:
« → a « a a + » »

There are many ways to skin a cat. You might strife to make your code fast or small or easy to understand.
Thus you may use local variables or then you may end up with unintelligible DUP ROT SWAP that you complained about.

As an example you may compare the program without and with using local variables to calculate the area and the centroid of a polygon.
In this case using local variables made the code faster, smaller and more intelligible.



Here's a Python program for the Zeller's congruence:
Code:
def dow(m, q, y):
    if m < 3:
        m += 12
        y -= 1
    K = y % 100
    J = y / 100
    return (q + 13*(m + 1)/5 + K + K/4 + J/4 - 2*J) % 7

And that's what I came up with for the HP-41C:
Code:
LBL "DOW"
STO 02 ; y
RDN
STO 01 ; q
RDN
STO 00 ; m
3
X<=Y?
GTO 00
12
ST+ 00 ; m
1
ST- 02 ; y
LBL 00
RCL 02 ; y
100
MOD
STO 03 ; K
RCL 02 ; y
100
/
INT
STO 04 ; J
RCL 01 ; q
RCL 00 ; m
1
+
2.6
*
INT
+
RCL 03 ; K
+
RCL 03 ; K
4
/
INT
+
RCL 04 ; J
4
/
INT
+
RCL 04 ; J
2
*
-
7
MOD
END

Compare the core of the calculation:
Code:
RCL 01 ; q
RCL 00 ; m
1
+
2.6
*
INT
+
RCL 03 ; K
+
RCL 03 ; K
4
/
INT
+
RCL 04 ; J
4
/
INT
+
RCL 04 ; J
2
*
-
7
MOD

with the corresponding part of the RPL program:
Code:
    q
    m 1 + 2.6 * IP +
    K + K 4 / IP +
    J 4 / IP + J 2 * -
    7 MOD

Can you recognise the similarities?



Quote:Max (still not convinced that RPL will ever be my thing)

It was never the purpose of my post to persuade anybody of this forum. My goal was to show similarities and then of course differences between these two systems.

For someone familiar with the HP-41C a lot of HP-48G's concepts are new:
  • local variables
  • structured data (lists, vectors, matrices, …)
  • structured programs (for- and while-loops, if- and case-statements, …)
  • errors

But then others like the use of RPN are just the same.

I was never much into the HP-50G. Even with the HP-48G I don't use all of its functions. But still I feel that I can write useful programs.

It's maybe similar to the “batteries included” philosophy of Python. You may never use all of the libraries but once you need to parse a JSON file it's nice that you can just use a function out of the box.

Chapter 29 Programmierung des HP 48 of the German Benutzerhandbuch is only 24 pages. Most of the stuff has already been handled within this thread.

Kind regards
Thomas
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Walkthrough of an RPL program for an RPN programmer - Thomas Klemm - 08-26-2018 03:37 AM



User(s) browsing this thread: 1 Guest(s)