Post Reply 
Access RPN stack result in PPL program?
09-04-2014, 10:26 PM
Post: #1
Access RPN stack result in PPL program?
How do I access the value in the lowest level of the RPN stack (x, level 1) in a PPL program?

The Ans function returns a list of the last pair of operands, rather than the result of the last operation.

Thanks.
Find all posts by this user
Quote this message in a reply
09-05-2014, 01:38 AM (This post was last modified: 09-05-2014 01:40 AM by oldhpfan.)
Post: #2
RE: Access RPN stack result in PPL program?
(09-04-2014 10:26 PM)gbh Wrote:  How do I access the value in the lowest level of the RPN stack (x, level 1) in a PPL program?

The Ans function returns a list of the last pair of operands, rather than the result of the last operation.

Thanks.

So far as I can tell there is no way to access the stack functions like echo from PPL as they seem to be interactive only (it would be nice if you could do something like x:= Echo(1); in a program and it would give you the value from level 1 of the stack, alas it doesn't work).
So unless someone out there knows how to do this the only work around I can think of would be to store the value from the stack into a variable and then use that variable in your program.
e.g.
5 Enter 'D' sto (put 5 on the stack as an example and store in the global variable D you could also create your own variable).
In the program you could square by doing: D:=D*D; or whatever you want to do with it. Remember it's a global variable so be careful as other programs could change the value.
Another option if you have several things on the stack would be to use the list stack function to create a list, store the list in a variable then access the list in your program.
Find all posts by this user
Quote this message in a reply
09-05-2014, 06:45 PM (This post was last modified: 09-05-2014 06:56 PM by John R. Graham.)
Post: #3
RE: Access RPN stack result in PPL program?
(09-04-2014 10:26 PM)gbh Wrote:  How do I access the value in the lowest level of the RPN stack (x, level 1) in a PPL program?
...
There is some access through the PPL function parameter and return value mechanisms. For example,
Code:
EXPORT ADD2(X,Y)
BEGIN
  RETURN X+Y;
END;
This program pops two values off of the stack, which end up in the variables X and Y, operates on those variables and returns the result, which is then pushed back onto the stack.

However, there's no ability to arbitrarily manipulate the stack outside the parameter / return mechanism. This is a capability I would sorely like to be added to the Prime: the stack needs to be a first-class citizen across the calculator.

- John
Find all posts by this user
Quote this message in a reply
09-06-2014, 03:23 AM (This post was last modified: 09-06-2014 03:39 AM by oldhpfan.)
Post: #4
RE: Access RPN stack result in PPL program?
There is some access through the PPL function parameter and return value mechanisms. For example,
Code:
EXPORT ADD2(X,Y)
BEGIN
  RETURN X+Y;
END;
This program pops two values off of the stack, which end up in the variables X and Y, operates on those variables and returns the result, which is then pushed back onto the stack.
- John
[/quote]

When I try to run this the calculator just asks for me to enter the X and Y parameters it doesn't take them from the stack. Nor does it return anything to the RPN stack.

Edit: Never mind, you have to run the program from home view and it works, if you do from the Program view the above problem happens.
Find all posts by this user
Quote this message in a reply
11-22-2014, 07:20 PM (This post was last modified: 11-22-2014 07:21 PM by jayhawk.)
Post: #5
RE: Access RPN stack result in PPL program?
You can read from the stack/history from PPL, no matter what mode you are in.
I use this tecknique to make my programs work in the same way in all three entry modes:
Code:

export showstack()
  local x,y,z,t;

  x:=Ans(1);
  y:=Ans(2);
  z:=Ans(3);
  t:=Ans(4);

  return {x,y,z,t};
end;
This program takes it's arguments from the stack/history no matter if the prime is in RPN, Textbook or Algebraic mode.

However it would be nice if you also could:
Code:

  Ans(2):=7*17;
It would also be nice if a program only returns a value if RETURN is used.
Then we would have an almost true RPN capable calculator!

PS:
My Prime:
Software Version: 2014 7 2 (6031)
Hardware Version: A
Find all posts by this user
Quote this message in a reply
Post Reply 




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