Recursive lambda functions?

Timon Gehr timon.gehr at gmx.ch
Mon Dec 30 13:58:28 PST 2013


On 12/30/2013 10:15 PM, Ilya Yaroshenko wrote:
> On Monday, 30 December 2013 at 12:24:28 UTC, lomereiter wrote:
>> Use Y combinator?
>> http://forum.dlang.org/thread/mailman.157.1385247528.2552.digitalmars-d-learn@puremagic.com#post-l6rgfq:24g5o:241:40digitalmars.com
>>
>
> This is not lambda =(
>
> I want something like
>
> enum factrorial5 = (a => a == 0 ? 1 : a * __lambda(a-1))(5);
> //Recursive pure lambda function


enum factorial5=(function int(a)=>a==0?1:a*__traits(parent,{})(a-1))(5);

(In D, you need to specify the return type for a recursive function
declaration. If one doesn't here, DMD crashes, which is a bug.
https://d.puremagic.com/issues/show_bug.cgi?id=11848)


More information about the Digitalmars-d-learn mailing list