[HP 50g] Evaluation in algebraics
09-13-2014, 01:32 PM
Post: #1
 ettlz Junior Member Posts: 20 Joined: Aug 2014
[HP 50g] Evaluation in algebraics
Is there any way for a program to tell if it's being evaluated from within an 'algebraic' as opposed to another RPL « program » or directly on the stack?

Also, it seems that when evaluating a (user) function, the 50g clears the stack before evaluating the function, packs what's left into a list, and restores the original stack with that results list pushed to Level 1. How is this done (and where is the stack's prior content held)?
09-13-2014, 06:45 PM
Post: #2
 DavidM Senior Member Posts: 847 Joined: Dec 2013
RE: [HP 50g] Evaluation in algebraics
(09-13-2014 01:32 PM)ettlz Wrote:  Is there any way for a program to tell if it's being evaluated from within an 'algebraic' as opposed to another RPL « program » or directly on the stack?

Don't know of any way to do this that uses standard system commands. Perhaps someone else does...

(09-13-2014 01:32 PM)ettlz Wrote:  Also, it seems that when evaluating a (user) function, the 50g clears the stack before evaluating the function, packs what's left into a list, and restores the original stack with that results list pushed to Level 1. How is this done (and where is the stack's prior content held)?

The developers of the Metakernel (used on the 49-50) came up with a concept they called a "Virtual Stack". There's a SysRPL API that includes a variety of Virtual Stack commands. Among other things, it allows a System RPL program to save/restore/manipulate the normal user stack as a single object in a virtual "stack of stacks". See this documentation (chapter 23) for a more complete description. You would need to be using SysRPL to access the Virtual Stack commands.
09-14-2014, 02:41 PM
Post: #3
 ettlz Junior Member Posts: 20 Joined: Aug 2014
RE: [HP 50g] Evaluation in algebraics
Thanks for the link. In fact I think it's the runstream control stuff that I need. The point of this exercise to implement a function with optional arguments (which can be done in User RPL thanks to the Virtual Stack stuff -- just call DEPTH -- but only if that function's only used in algebraics; it obviously gets messy when called elsewhere).
09-14-2014, 05:26 PM
Post: #4
 DavidM Senior Member Posts: 847 Joined: Dec 2013
RE: [HP 50g] Evaluation in algebraics
(09-14-2014 02:41 PM)ettlz Wrote:  Thanks for the link. In fact I think it's the runstream control stuff that I need. The point of this exercise to implement a function with optional arguments (which can be done in User RPL thanks to the Virtual Stack stuff -- just call DEPTH -- but only if that function's only used in algebraics; it obviously gets messy when called elsewhere).

You could probably call some of the Virtual Stack commands with SYSEVALs, but they're normally only used from SysRPL (as opposed to User RPL). Runstream control as well, and many of the runstream commands don't really apply outside of a SysRPL context.

One way to handle optional arguments in User RPL code is to put the optional parts in a list. Many of the built-in functions already know how to deal with that type of operation, so it could even simplify your code. In that context, the list itself implies the depth of the optional parts. A similar alternative might be to use a "meta structure", where you place your arguments on the stack and then a number in stack level 1 to designate the actual argument count. Both of these methods have their own strengths depending on the situation.

Hope this helps!
09-14-2014, 05:42 PM
Post: #5
 ettlz Junior Member Posts: 20 Joined: Aug 2014
RE: [HP 50g] Evaluation in algebraics
(09-14-2014 05:26 PM)DavidM Wrote:  You could probably call some of the Virtual Stack commands with SYSEVALs, but they're normally only used from SysRPL (as opposed to User RPL). Runstream control as well, and many of the runstream commands don't really apply outside of a SysRPL context.
I was thinking of creating a SysRPL function called, say, ARGC that detects when it is called within an algebraic and in that case does DEPTH, otherwise it pushes -1.
(09-14-2014 05:26 PM)DavidM Wrote:  One way to handle optional arguments in User RPL code is to put the optional parts in a list.
That would be ideal, and is how I would like to do it, but the traditional '' syntax doesn't allow inline lists. (The new  does, which is nice but I'd like to try and get this working for old-style symbolics.)
 « Next Oldest | Next Newest »

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