Post Reply 
RPL second impressions (HP 28)
06-30-2018, 01:20 AM
Post: #24
RE: RPL second impressions (HP 28)
(06-29-2018 07:14 PM)Thomas Okken Wrote:  You still have to expend way too much mental energy to keep track of what is where in the stack.

Instead of 3 values only one is permanently on the stack. It's the divisor that is incremented by 2 with each step in the DO-loop:
Code:
        2 +

You may call it d or if you prefer OVER.

Quote:"r OVER < OVER n SWAP MOD NOT OR" is only "easy to read" for very specific values of "easy." Smile

There's a reason I wrote this as:
Code:
        r OVER <
        OVER n SWAP MOD NOT
        OR

Using the variable d instead that would be:
Code:
        r d <
        d n SWAP MOD NOT
        OR

That's the combination of two predicates using or.
In Python that would be:
Code:
r < d or n % d == 0

So there's left only one relevant stack operation: SWAP.

In Forth we would probably factor this as:
Code:
: DIVIDES SWAP MOD NOT ;

This would lead to:
Code:
        r d <
        d n DIVIDES
        OR

While we could extract that in UserRPL as code object in a local variable we'd still have to EVAL it. That's the reason I would avoid that. And then I assume it would be slow.

Hopefully I reduced the mental energy needed to read that piece of code once more.
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) - 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) - Thomas Klemm - 06-30-2018 01:20 AM
RE: RPL second impressions (HP 28) - ttw - 07-04-2018, 10:52 PM



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