Declare:
def fname( args ) { pass; }
Sometimes you need to declare functions (ex: the dragon algorithm).
args = {a, b, c, ...} or {}
Examples:
def f(a) {
print a;
}
def g(a, b) {
start
c := a + b;
print c;
end
}
/!\ Variables are local (cannot use variables outside of the function).
Recursive example:
def p(a, b) {
start
c := 1;
if (b > 0) {
c := a * p(a, b-1);
}
elif (b < 0) {
c := 1 / p(a, 0-b);
}
end
return c;
}
Functions can be used in expressions:
a := p(2, 10);
print a;