HP Forums
how to programatically define - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: how to programatically define (/thread-7311.html)

how to programatically define - primer - 11-26-2016 04:15 PM

As you know define (shift-template key) allow you to define a function with parameters.
how can we define such a function from HPPL program ?

Is there something like : Define("abc","A*2+B") ?


RE: how to programatically define - cyrille de brébisson - 11-28-2016 07:13 AM


Yes, you can actually do it, but it is a little bit cumbersome, sorry about that...

Defined functions are actually user system global variables that contains a user function (a user function is different from an expression. A user function is an instruction sequence (ie, an executable list of objects) that has named parameters).

However, contrary to the CAS system, which is formal, there is no syntax for a user to enter/create such an object in the command line (although there is one in program mode).

As a result, you need to jump through hoops to do "make it happen".
So, without further due, here is how to do it!

First, define a user system global variable using the HVars instruction:
Then, and this is where the trick is, you need to tell the system to convert that expression into a user function with given parameters.
Do this using the 2nd meta data of the abc variable.
This tells the system that the variable abc is now a user function and that it takes 1 parameter (ie local variable) called B.

You can provide as many parameters as you want of course, and the order in which you give them is the order in which they appear in the parameter list.

Note, this works both ways, you can get the parameter list of an existing user defines function by doing HVars("name", 2)

By the way, this is explained in the help (not as extensively as here)


RE: how to programatically define - primer - 11-28-2016 11:35 PM

Thank you Cyrille,
that's impressive !
and it works really good.

(11-28-2016 07:13 AM)cyrille de brébisson Wrote:  By the way, this is explained in the help (not as extensively as here)
yes, but I didn't make the link with HVars. (I pressed help on Define screen)


RE: how to programatically define - Brad Barton - 12-06-2016 04:41 AM

Since HVars appears in the Help menus, but I don't seem to be able to access from the catalog, it seems like a semi-documented function. Looks like a really nice way to define functions programatically if you want to create an environment for dealing with specific classes of equations.

Is there any documentation outside of the Help menus that shows these types of commands and how they're used?

RE: how to programatically define - cyrille de brébisson - 12-06-2016 06:23 AM


HVars is located in the Vars/Home/System menu.

I am sorry, but I do not have an extensive list...


RE: how to programatically define - Brad Barton - 12-07-2016 05:48 PM

Thanks for the pointer Cyrille!