Skip to content

Recursion

Recursive functions

Functions may be recursive.

function recursive(n: Number) returns Boolean -> {
    return if (n > 0) {
        recursive(n - 1);
    } else {
        true;
    };
};

Recursive permissions

Protocol actions may be recursive.

protocol[party] RecursiveProtocol() {
    permission[party] recursive(n: Number) returns Boolean {
        if (n > 0) {
            return this.recursive[party](n - 1);
        } else {
            return true;
        };
    };
};

Highly recursive invocations can lead to StackOverflow exceptions, and may indicate the need for a different implementation.