Post Reply 
RPL equivalents to BREAK, CYCLE, EXIT, etc.?
06-09-2014, 07:43 PM
Post: #20
RE: RPL equivalents to BREAK, CYCLE, EXIT, etc.?
(06-09-2014 04:24 PM)DavidM Wrote:  Before I even responded to Thomas, I realized that he intentionally chose an example that was biased toward using something like a BREAK.

My intention was to provide an example where eliminating the BREAK isn't trivial. I knew you couldn't use the FOR-loop and then you had to find a way to access the outcome of hasDivisor outside the loop. Throwing an error allows to pass that information without using a local variable.

I guess the most difficult part in my program is to figure out the next step after DROP:
Code:
    NEXT DROP
  THEN 0
  ELSE 1
In a longer program this can be multiple lines away from the condition.

And I agree with you: reasoning about a program is more difficult if there are multiple exit points.
I like your solution: By using meaningful names for the variables the intent is made clear.

Let me add a 3rd more functional variant:
Code:
\<< \-> n
  \<<
    'n MOD ?' ? 2 n \v/ 1 SEQ
    \<< AND \>> STREAM
  \>>
\>>
It doesn't work for small numbers and it doesn't short-cut when the first factor is found. But if the sequence was evaluated lazy the calculator could do that for us.

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


Messages In This Thread
RE: RPL equivalents to BREAK, CYCLE, EXIT, etc.? - Thomas Klemm - 06-09-2014 07:43 PM



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