The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

HP50g: Writing a function that returns a function
Message #1 Posted by Chris de Castro on 10 Dec 2013, 6:18 p.m.

On the HP-50g, how does one convert an expression into a function programmatically? e.g. I have an expression x^2+1 and wish to convert it into the function << ->x 'x^2+1' >>. More generally, how does one return a program << ... etc... >> from a program? (Haven't hit on the proper syntax yet). Thanks for your assistance.

Appreciatively, Chris

      
Re: HP50g: Writing a function that returns a function
Message #2 Posted by Han on 10 Dec 2013, 6:48 p.m.,
in response to message #1 by Chris de Castro

Quote:
On the HP-50g, how does one convert an expression into a function programmatically? e.g. I have an expression x^2+1 and wish to convert it into the function << ->x 'x^2+1' >>. More generally, how does one return a program << ... etc... >> from a program? (Haven't hit on the proper syntax yet). Thanks for your assistance.

Appreciatively, Chris


One method is through strings. For example:

<< -> f << "<< -> x '" f + STR-> >>

could work, provided that the formula is in terms of lower-case 'x'. Enter a formula on the stack (with the single quotes) and evaluate this program to get the desired result. I don't remember if there is an RPL command that extracts the variable of a given expression (my bad memory thinks there is), but hopefully the example above gives you some ideas.

Edited: 10 Dec 2013, 6:48 p.m.

            
Re: HP50g: Writing a function that returns a function
Message #3 Posted by Han on 10 Dec 2013, 6:49 p.m.,
in response to message #2 by Han

If you are trying to create mathematical functions, you can alternatively use the DEFINE command.


[ Return to Index | Top of Index ]

Go back to the main exhibit hall