Functions are created using the function keyword. The example below creates a simple function which prints a friendly message. The function must conclude with the "end" statement.
The function below takes no arguments as input:
function foo() // declare the function
print("hello")
end
foo() // call the function
hello
The function below takes three arguments as input and returns a value:
function Addition (a,b,c) // the three arguments are input to the function
d = a+b+c
return (d)
end
t = Addition(2,3,4)
print("t is",t)
> t is 9
The function below takes variable number arguments as input and returns a value:
function Addition (...) // the three dots constitute variable number of arguments
num = arg.n //number of arguments passed to the function
i = 1;
d = 0;
while (i <= num) {
d = arg[i]+d;
i = i+1;
}
return (d)
end
t = Addition(2,3,3)
print(t)
>t is 8
> print(foo) // get the value of the variable "foo"
function: 0566AA28
A random number is generated above.
For more information on HyperMath function types, see Defining Functions.