Lambda functions in D

Timon Gehr via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat May 9 04:49:47 PDT 2015


On 05/09/2015 01:20 PM, Dennis Ritchie wrote:
> Hi,
> Can lambda functions or delegates in D to call themselves?
> Can I write something like this:
>
> -----
> import std.stdio;
>
> void main() {
>
>      auto fact = function (int x) => x * { if (x) fact(x - 1); };
>
>      assert(fact(10) == 3628800);
> }

assert((function int(int x)=>x?x*__traits(parent,{})(x-1):1)(10)==3628800);


More information about the Digitalmars-d-learn mailing list