Walkthrough of an RPL program for an RPN programmer
08-26-2018, 03:37 AM
Post: #21
 Thomas Klemm Senior Member Posts: 1,448 Joined: Dec 2013
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
08-26-2018, 06:43 PM
Post: #22
 pier4r Senior Member Posts: 2,016 Joined: Nov 2014
RE: Walkthrough of an RPL program for an RPN programmer
(08-25-2018 01:35 PM)Maximilian Hohmann Wrote:  Hello!

As I am quoted in the original and really excellent (!) post of this thread I need to comment quickly... (have been away for work last week and couldn't do it earlier).

Having read the posting and the replies shows me several things:

1. RPL is not RPL, not even within HP.
2. RPL experts are not RPL experts, at least every one seems to use it in his own special way.
3. RPL is definitely not for the occasional user.
4. Some RPL implementations are exrtemely powerful. 2500 built in functions. Impressive! But who remembers all those when he needs them?

1. That's normal. things evolve. You can do things with awk 4.1 that are much different with awk 2.x . That is true for any language that evolved slowly over time. I'd say that it is life. A bit like German, you cannot say that the German today is the same of 150 years ago, but it is has the same name.

2. True and false. Everyone in every language has his style unless there is a mainstream guideline how to write code. In any case the important part is that "obscure" things can be explained. And there are few RPL experts here, the others (like me) are at most power users.

3. I do agree, unless the program is trivial. But which language is for an occasional user? I am interested here. Maybe basic?

4. There is the manual. 2500 functions (or let's say: 2500 non trivial words in a dictionary) are plenty, either one uses them night and day or one needs a lookup (and online discussion or community help too). And I strongly disagree with "less is more". No, to keep down development time having a function ready made, reliable and quite fast is gold.

"Oh I want to SORT a list". Too bad, SORT doesn't exist. "Well I can use DOSUBS". Too bad, dosubs doesn't exists too. That's a lot of overhead only for sort. Without entering the realm of math functions.

The RPL library, even without additions, is something amazing. It covers a lot of needs. I wish the 50g had more ram . But I need to push the prime too.

Wikis are great, Contribute :)
 « Next Oldest | Next Newest »

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