Code from a Rosetta Code Task

Meta jared771 at gmail.com
Thu Aug 29 11:57:56 PDT 2013


uint fib(in uint n) pure nothrow {
     immutable self = &__traits(parent, {});
     return (n < 2) ? n : self(n - 1) + self(n - 2);
}

I came across this while browsing Rosetta Code. It's really cool 
how you can do recursion without anonymous functions (and this 
will actually not work if you make fib a delegate). However, I'm 
confused about the __traits(parent, {}) part, specifically , the 
{} passed to parent. Does {} just mean the outer scope?


More information about the Digitalmars-d-learn mailing list