reference to 'self' inside a function
Kevin Cox
kevincox.ca at gmail.com
Tue Jul 17 16:05:30 PDT 2012
On Jul 17, 2012 6:50 PM, "Era Scarecrow" <rtcvb32 at yahoo.com> wrote:
>
> On Tuesday, 17 July 2012 at 22:13:13 UTC, Eyyub wrote:
>>
>> 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.
>>
>>
>> Good idea !
>> "self" is a cute keyword, or "lambda" but this could break existing code.
>
>
> Mmm.. Why not an inner function to represent the recursive function? True
a 'self' reference may resolve the issue,
What about how JavaScript does it. Anonymous functions can still have a
"name" that can be used from inside of a function to refer to itself.
And the most useless example ever.
var f = function func ( i ) {
return func(7);
};
I think that this is nice because there is no name space pollution, no new
keywords needed and it is pretty.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120717/f0a755c2/attachment.html>
More information about the Digitalmars-d
mailing list