Code from a Rosetta Code Task

Robik nomail at foo.com
Thu Aug 29 14:00:49 PDT 2013


On Thursday, 29 August 2013 at 18:57:58 UTC, Meta wrote:
> 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?

{} in this case is just empty delegate function.


More information about the Digitalmars-d-learn mailing list