Skip to main content
Version: 1.6.0

Recursion

Recursive functions are defined and called using the same syntax as non-recursive functions.

function sum (n: int, acc: int) : int {
if (n < 1) return acc else return sum (n-1, acc + n);
};
function fibonacci (n: int, n_1: int, n_0: int): int {
if (n < 2) return n_1 else return fibonacci (n-1, n_1 + n_0, n_1);
};

This means that all values, including functions, declared in the same block or top-level scope, must have different names, because they can all potentially be mutually recursive.