newRPL: Alpha demo 0.9 released [UPDATED 2017-10-25]
08-14-2017, 02:26 AM
Post: #11
 Claudio L. Senior Member Posts: 1,674 Joined: Dec 2013
RE: newRPL: Alpha demo 0.9 released [UPDATED 2017-08-11]
(08-14-2017 12:47 AM)smartin Wrote:  Just a few comments/questions on the new commands.

POSREV- I can see this giving the reverse position for strings, but not for lists (in which POS and POSREV return the same position).
Confirmed. Will upload an updated ROM in a couple of days, thanks for the report.

(08-14-2017 12:47 AM)smartin Wrote:  What does NPOS/NPOSREV do?
Same thing, but starting the search from given position N instead of the beginning. If POS returns position 'p', just pass 'p+1' to NPOS to find the next ocurrence.

(08-14-2017 12:47 AM)smartin Wrote:  SPUSH, SPOP, SDROP - Nothing seems to happen when I try and use these. I was expecting that SPOP after doing an SPUSH would restore the previous stack contents.

They work as intended. You need to consider that they do the same as the automatic UNDO feature. So if you run SPUSH from the menu, the only effect you'll notice when you press the left cursor to UNDO, you'll have to press it twice, as there will be 2 identical copies of the stack, one made automatically when you pressed the menu, and the second one done by SPUSH. When you run SPOP from the menu, it pops the UNDO information that's created automatically when you pressed the menu, so you'll notice if you change the stack and then press left, the previous stack won't be there.

To see the real effect, it's best to use them in a program:
Code:
 << 1 2 3 SPUSH 4 5 6 >>
You should see whatever you had on the stack, and 1 2 3 4 5 6. If you press the left cursor to UNDO, you'll see the 4 5 6 vanish, but the 1 2 3 still there (that's the snapshot taken by SPUSH), and if you UNDO again you'll be back at the stack you had when you ran the program, that's a snapshot taken automatically when you pressed either EVAL or the menus.

Code:
 << SDROP INV SPUSH INV >>
This example will first remove the automatic UNDO snapshot, invert a number, then take a snapshot and finally invert it again. If you have a 3 on the stack, you'll see the same 3 at the end of the program, but if you UNDO with left cursor, you'll have 0.3333333... instead of the 3.

The idea is you can SPUSH the original stack state, then explode a list or something like that, and if you encounter an error, you can trap it and do an SPOP before ending your code with a DOERR or BLAMEERR. It makes for a much cleaner exit on complex programs.

BTW, I added how to use SETNFMT in the "Formatting Numbers" section to the wiki, that's one of the new features that needs testing too, please test.
 « Next Oldest | Next Newest »