FUNCTION

Syntax: #FU name value

This command is used to create a user-defined function. Name is the name of the function, and value is an expression to assign to the function. You can use the parameters %1 to %99 to refer to arguments passed to your function.

FUNCTION Examples

#FU fact {%if(%1<=1,1,%1*@fact(%eval(%1-1)))}
creates a user defined function to compute the factorial of a number. If the argument is less than or equal to one, one is returned, otherwise the argument is multiplied by the factorial of the argument minus one. Note that arguments to functions are normally just expanded and not evaluated, so we need the %eval function to force the subtraction of one.
 
#EVAL @fact(5)
will display 120 given the above definition
 
#SHOW @fact(5)
will display 5*4*3*2*1 given the above definition


Contents FREEZE GAG