A Tour of Morfa

Nested functions

Functions can be nested inside other functions. A nested function may access local variables of the enclosing function.

import morfa.io.print;

unittest
{
    var timesGreeted = 0;

    func greet(who: text)
    {
       printf("Hello, {}!\n", who);
       timesGreeted += 1;
    }

    greet("world");
    greet("Morfa");
    assert (timesGreeted == 2);
}