HP Forums

Full Version: how to programatically define
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
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") ?

Regards.
Hello,

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:
HVars("abc"):='A+2*B'
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.
HVars("abc",2):={"B"}
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)

Cyrille
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)

thanks.
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?
Hello,

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

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

Cyrille
Thanks for the pointer Cyrille!
Brad
Reference URL's