Re: HP Prime - RPN stack access from programs? Message #6 Posted by Mike Mander (Canada) on 30 Sept 2013, 3:07 p.m., in response to message #4 by Tim Wessman
Hi Tim,
Since programs are available no matter what mode (Home/CAS) or what app is currently active, these functions should work anywhere. Personally, I would be happy with the following...
ANS(n) - Accesses the current stack, whether it be RPN or the other non-RPN history stacks in Home or CAS. Examples: ANS(2):=5; would write 5 to stack level 2. X:=ANS(3) would make X equal to what is on level 3 etc. Alternatively, instead of array access like this, read/write functions would be fine too but an ANS(n) array is more elegant perhaps.
CALCMODE - returns a number indicating which mode the calculator currently is in. For example, 0:CAS 1:Home/Textbook 2:Home/Algebraic 3:Home/RPN.
SETMODE(n) - Sets the current mode of the calculator as above. That way, if you wanted to retrieve something from level 1 of the CAS stack, you could do so even if in a different mode (RPN for example) as follows: temp:=CALCMODE; SETMODE(0); X:=ANS(1); CALCMODE(temp);
DEPTH - returns the current stack depth.
POP(n) - Pop n values off the stack, effectively discarding them. POP(-1) could be used to clear the stack of all entries (or just POP(DEPTH) I suppose). This would make reading a value off the stack and popping it off a two stage process (ex. X:=ANS(1); POP(1);) but I certainly could live with that.
[edit: I suppose the above should be called DROP(n) and not POP(n) perhaps?]
PUSH(x) - Push the number/expression 'x' onto the stack. Or...
The above -PUSH(x)- is a little inconsistent I suppose, so perhaps instead of PUSH(x), there should be...
PUSH(n) - pushes up the stack n times, leaving zeros on created levels. Then, instead of a PUSH(x) to put 'x' on the stack level 1, you would PUSH(1); ANS(1):=X; and to put two results on the stack for example, it would be PUSH(2); ANS(2):=Y; ANS(1):=X; which is more consistent, but a little more work when you have to use it.
TYPE(n) - indicates what type the object on stack level n is, for example is it a real number, a complex number, a list, an array, an equation and so on.
Of course other functions would be useful, similar to the 50g, so ROLLD, SWAP and so on, but with the above functions, if I needed that level of stack control in a program I could always implement those functions myself. I'm sure others will disagree and wish for more stack control, but even rudimentary access as I've outlined above would a lot better than nothing in my view.
Anyway, that's a start perhaps? I'm probably forgetting something important and I may certainly not understand all the architectural subtleties of the HP Prime. I am still surprised that there apparently is no way to do this already, but I hope something like that could be implemented!
While I am in "wish-list" mode :-), I might as well also mention that being able to organize programs and variables into directories would be very much appreciated too! I had plans to transfer (rewrite) a fair number of programs I had in my 50g for the Prime, but the program and user variable menus will probably get horribly cluttered if I keep things as modular as I did on the 50g. Also, a revert and/or undo command when editing a program would be nice too.
However for the moment, the Prime looks very promising and with a few tweaks here and there, I could see it replacing my 50g. I appreciate all the effort Tim and the rest of the HP Prime team have made since this is truly an awesome new computing tool! I am very glad that progress is being made in the sense that we have a modern new calculator platform going forward, and not just another version of the 48/49/50. That said, a "60g", based on the 50g but with a high-res colour touchscreen, faster CPU, Li-Ion battery and maybe even the Prime's BASIC language for programming, along with the traditional RPL still, would be pretty darn nice too... :-)
Edited: 30 Sept 2013, 3:13 p.m.
|