[HP 50g] Evaluation in algebraics - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: [HP 50g] Evaluation in algebraics (/thread-2131.html) |
[HP 50g] Evaluation in algebraics - ettlz - 09-13-2014 01:32 PM 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)? RE: [HP 50g] Evaluation in algebraics - DavidM - 09-13-2014 06:45 PM (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. RE: [HP 50g] Evaluation in algebraics - ettlz - 09-14-2014 02:41 PM 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). RE: [HP 50g] Evaluation in algebraics - DavidM - 09-14-2014 05:26 PM (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! RE: [HP 50g] Evaluation in algebraics - ettlz - 09-14-2014 05:42 PM (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.) |