reference to 'self' inside a function
Nathan M. Swan
nathanmswan at gmail.com
Thu Jul 19 23:35:52 PDT 2012
On Tuesday, 17 July 2012 at 16:56:17 UTC, angel wrote:
> I propose to introduce a reference to the current function,
> much like 'this' in a class method. Call it 'self' or
> 'thisFunc', or whatever ...
> What might this be good for ?
> For implementing recursion in a lambda function.
> Writing in functional style, one creates many functions, and
> looking for reasonable names for these functions becomes
> unnecessarily painful.
May I suggest the "recur" or "recursive" keyword?
auto factorials = map!(n => n ? n * recur(n-1) : 1)([1, 2,
3]).array;
assert(factorials == [1, 2, 6]);
NMS
More information about the Digitalmars-d
mailing list