Fibonacci Example

Calculates the n-th Fibonacci number.

Code:

module body Fib is
    function fib(n: Nat64): Nat64 is
        if n < 2 then
            return n;
        else
            return fib(n - 1) + fib(n - 2);
        end if;
    end;

    function main(): ExitCode is
        print("fib(30) = ");
        printLn(fib(30));
        return ExitSuccess();
    end;
end module body.

Compile:

austral compile fib.aum --entrypoint=Fib:main --output=fib

Output:

fib(30) = 832040