Post Reply 
RPL second impressions (HP 28)
06-27-2018, 03:41 AM (This post was last modified: 06-27-2018 03:42 AM by Joe Horn.)
Post: #5
RE: RPL second impressions (HP 28)
EDIT: Oops... I see that while I was writing the following DavidM beat me to it! Smile

Ah, the joys of learning RPL! Welcome to the club!

(06-27-2018 01:19 AM)mdunn Wrote:  3. Wonder if IF..THENs can be nested...

Yes. See the Advanced Users Reference Manual, page 2-25 (that's one page, not a range) for an example of nested conditionals.

RPL allows everything (*) to be nested as many levels deep as you want, limited only by its available memory and your available patience. Big Grin A fun example is the →RPN program on page 2-28, which has an IF/THEN nested inside a FOR/NEXT loop which is nested inside an IF/THEN!

* Gentle Reader: If there's anything that RPL doesn't allow to be nested, please correct me.

Fleeting thought: Some nested IF/THEN structures are more efficiently coded (and more human-readable) using the CASE structure instead.

(06-27-2018 01:19 AM)mdunn Wrote:  4. I find the multiple ways of writing things a tad confusing (RPN, algebraic, etc?).
Here's just one example from my Primes thingy:

pseudocode:
IF FRAC(a/b)==0 THEN ...

Translates, I think, to something like:

RPN:
IF a b / FP 0 == THEN ... END
tho I guess this would be even MORE RPNish:
a b / FP 0 == IF THEN ... END
or:
a b / FP 0 IF == THEN ... END
:-)

Since THEN treats 0 as false and any nonzero value as true, you can replace 0 == with just NOT in all of the above (e.g. IF a b / FP NOT THEN ... END), which makes the code slightly shorter and faster but cryptic to any human reader who doesn't know how THEN works.

(06-27-2018 01:19 AM)mdunn Wrote:  Algebraic:
IF 'FP(a/b)==0' EVAL THEN ... END
THAT one took a while to figure out!

As the AUR mentions on pages 1-13 and 3-112, "If the test-clause is an algebraic, it’s automatically evaluated to a number — you don’t need →NUM or EVAL." Therefore IF 'FP(a/b)==0' THEN ... END and IF 'NOT FP(a/b)' THEN ... END also work (with the EVAL omitted).

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RPL second impressions (HP 28) - mdunn - 06-27-2018, 01:19 AM
RE: RPL second impressions (HP 28) - Joe Horn - 06-27-2018 03:41 AM
RE: RPL second impressions (HP 28) - mdunn - 06-27-2018, 01:58 PM
RE: RPL second impressions (HP 28) - mdunn - 06-27-2018, 04:06 PM
RE: RPL second impressions (HP 28) - mdunn - 06-27-2018, 05:11 PM
RE: RPL second impressions (HP 28) - mdunn - 06-27-2018, 07:45 PM
RE: RPL second impressions (HP 28) - mdunn - 06-28-2018, 08:48 PM
RE: RPL second impressions (HP 28) - ttw - 07-04-2018, 10:52 PM



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