Post Reply 
Can 50g sysRPL jump to lables?
10-30-2018, 11:32 AM
Post: #17
RE: Can 50g sysRPL jump to lables?
(10-30-2018 10:49 AM)3298 Wrote:  
(10-30-2018 02:31 AM)BlackMi Wrote:  This is a loop
BEGIN
condition
WHILE
code
REPEAT

but
::
BEGIN
condition
NOTcase AGAIN
code
AGAIN
;
RDROP
does the same thing.
What happened in the process? Should not the first AGAIN loop to the BEGIN running the condition over and over again?
I think I have seen that code before. You're looking at the programming tricks from Nosy's Readme, right? That's some advanced runstream juggling, so if you don't understand it, start with the simple stuff like merely going up more than one level of secondary nesting (straightforward solution: RDROP at the end of one secondary, so the ; after it pops an older entry off the return stack).

Anyway, the command "case" (and by extension NOTcase which just swaps the effects of the boolean input on the data stack) pops one object off the runstream (here: the command AGAIN), pops one boolean off the data stack, and depending on the value of the boolean it either just finishes (causing whatever is after the object to get executed; here that's whatever "code" gets substituted for), or it pops the topmost pointer off the return stack into the current runstream and then executes the object. The important bit is the return stack popping: that removes the value BEGIN has put there, so AGAIN will use a different one. That will be the runstream pushed by the :: before the BEGIN command (which searched for its corresponding ; and pushed a pointer to what comes after that).
The next question to ask is what AGAIN actually does with the value on the return stack. In an ordinary loop BEGIN simply pushes the current runstream onto the return stack, and AGAIN copies it back into the current runstream without popping it - this is how they work together to create a potentially infinite loop. In this piece of code NOTcase has removed the runstream pushed by BEGIN from the return stack and made it the current one, but before anything from that gets executed, AGAIN gets its chance - it will immediately replace the current runstream again, this time with the runstream of the secondary that called the :: ; embedded in this snippet. The first object in that is RDROP, which gets rid of the runstream AGAIN used but left on the return stack.
In case you wonder why AGAIN and RDROP aren't combined into a single command: That command may exist (it's called SEMI), but because it's an alias for ; it has the side effect of marking the end of the secondary. If the compiler wouldn't complain about the extra ; a few lines below, then using SEMI in place of the first AGAIN and omitting the RDROP would cause the code run on encountering :: to advance the runstream it pushes to the return stack only past that, not past the ; near the end of the snippet.

Thank you very much!
Yes, I am reading Nosy's Readme. It gives details of some RPL objects. How System RPL executing them is still not clear.
It takes time for me to understand the whole thing. Smile
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Can 50g sysRPL jump to lables? - BlackMi - 10-22-2018, 07:09 AM
RE: Can 50g sysRPL jump to lables? - 3298 - 10-22-2018, 10:11 AM
RE: Can 50g sysRPL jump to lables? - 3298 - 10-29-2018, 01:36 PM
RE: Can 50g sysRPL jump to lables? - 3298 - 10-30-2018, 10:49 AM
RE: Can 50g sysRPL jump to lables? - BlackMi - 10-30-2018 11:32 AM
RE: Can 50g sysRPL jump to lables? - 3298 - 10-30-2018, 03:36 PM
RE: Can 50g sysRPL jump to lables? - 3298 - 10-30-2018, 04:54 PM



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