Documentation

Functions

Function exampleFunctions are similar to Aliases except that they can return a value like a variable. In fact, a Function is called like a variable, using the @ character, with an optional list of arguments separated by commas and enclosed in parenthesis.

For example:

#FUNCTION MySum($a,$b) {#RETURN ($a+$b)}
Creates a function that returns the sum of it's given two arguments. For example, @MySum(1,3) would return the value of 4.

#FUNCTION MySum {$val=0;#LOOP %numparam {$val = $val + %param(%i)};#RETURN $val}
Creates a function that returns the sum of it's arguments and handles any number of arguments (up to 99). For example, @MySum(1,3,4) would return the value of 8.

Inline Functions

You can create special Variables that also work like "inline" functions and do not require the #RETURN command. These inline functions are defined using the #VARFUNC command. For example:

#VARFUNC MySum($a,$b) {$a+$b}
Creates an inline function that returns the sum of it's given two arguments. @MySum(1,3) will return the value of 4, just like in the first example of #FUNCTION.

Notice that inline functions only contain a single expression that is returned (so no #RETURN command is needed). Regular functions defined with #FUNCTION can contain any sort of processing, loops, conditions, etc and can be much more complex than simple inline functions.

NOTE: Full functions were added in v2.0. In versions prior to 2.0, the #FUNCTION command created an "inline" function and there wasn't any #VARFUNC command.

Add comment

Login or register to post comments