List Commands Library for 50g
|
09-07-2017, 07:54 PM
Post: #127
|
|||
|
|||
RE: List Commands Library for 50g
(09-06-2017 04:55 PM)3298 Wrote: DO ... LOOP doesn't use the return stack, so combining these may be a simple way to avoid that RSWAP hassle while keeping the benefits. I'd love to avoid the RSWAPs if I could, but I thought they were still needed inside the DO...LOOP structure. I found where I originally saw the technique: STREAM. It was my first introduction to the concept. It's small enough to use as an example of this concept for any folks that wish to follow along here. I've included the code below, along with some comments to help others understand what we're talking about. Credit where due: this isn't my code, but rather the actual built-in code for STREAM. The comments were added to help understand what it is doing. As a reminder, UserRPL STREAM puts the first two elements of a list on the stack, then executes the prog/function you give it, then does the same with the rest of the elements. Here's how it does this: Code: :: Stepping through the above code with the debugging tools shows that the RSWAPs are necessary. Now, to follow my own advice from another post about learning from others, I'll attempt to convert the above code into an alternative form using 3298's ticR suggestion in place of 'R. I'll skip the loop structure optimization for now to avoid confusion, and this time without the comments to show how small this command really is: Code: :: (09-06-2017 04:55 PM)3298 Wrote: I guess you read the text file that comes with Nosy? It contains some programming tricks in its last section. ... Thanks for the reminder to go back and take a look at it. I did see that (a long time ago), but must confess that I didn't take the time to digest that section at the time. Your examples are good ones for the power of the optimizations you (and Werner) are using. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 5 Guest(s)