Post Reply 
RPN stack I/O from PPL
05-16-2018, 06:15 AM
Post: #1
RPN stack I/O from PPL
Here is a workaround to allow reading and writing back to multiple stack locations from PPL
It uses the fact that a key definition returns a string to the command line without quotes. So RETURN "stack1 stack2 stack3 stack4" will place those vars onto the lowest 4 stack levels on pressing <ENTER>

In the code below , global vars are created to hold the stack values.
Ans(1) to Ans(4) are used to pop 4 values from the stack.
a sample routine then takes the factorial of the stack values.
on pressing SHIFT User 0, stack4 stack3 stack2 stack1 is placed on the command line, and <ENTER> pushes them onto stack.

try this:
Home screen RPN mode
place on stack:
2 <ENTER>
4 <ENTER>
6 <ENTER>
8 <ENTER>
Shift User 0
stack4 stack3 stack2 stack1 is returned
<ENTER>

2
24
720
40320
is returned to the stack

Code:

EXPORT stack1,stack2,stack3,stack4; //global stack vars
KEY K_0()
BEGIN
//pop 4 items from stack
Ans(1)▶stack1;Ans(2)▶stack2;Ans(3)▶stack3;Ans(4)▶stack4;

//routines go here
stack1!▶stack1; 
stack2!▶stack2; 
stack3!▶stack3;
stack4!▶stack4;

//push 4 items to stack. Detect Entry and return array if not RPN mode
RETURN  IFTE(Entry==2,"stack4 stack3 stack2 stack1","{stack4,stack3,stack2,stack1}");
END;
Find all posts by this user
Quote this message in a reply
Post Reply 




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