Calling anonymous delegate recursively ?

Andrej Mitrovic andrej.mitrovich at gmail.com
Sat Jan 8 09:40:43 PST 2011


As a workaround you can do this for now:

import std.stdio;

enum deleg = returnFib();
ulong delegate(ulong m) returnFib()
{
    return (ulong m)
    {
        if(m < 2)
            return m;
        return deleg(m-1)+deleg(m-2);
    };
}

void main()
{
    writeln(returnFib()(10));
}

Otherwise I'd really like the ability for a lambda to call itself.
Perhaps a feature request is in order.


More information about the Digitalmars-d-learn mailing list