On 08/29/2013 08:53 PM, Meta wrote:

> However, after some fiddling, it seems that this is actually not usable with
> anonymous functions, or at least, I couldn't find a way to do it.

Borrowing the "self" trick from the existing solution, the following satisfies all of the requirements:

int fib(int arg) pure {
    enforce(arg >= 0);

    return function int (int n) pure nothrow {
        auto self = __traits(parent, {});
        return (n < 2) ? n : self(n - 1) + self(n - 2);
    }(arg);
}

Ali

Reply via email to