reference to 'self' inside a function
H. S. Teoh
hsteoh at quickfur.ath.cx
Tue Jul 17 11:32:44 PDT 2012
On Tue, Jul 17, 2012 at 01:09:09PM -0400, Kevin Cox wrote:
> On Jul 17, 2012 1:00 PM, "angel" <andrey.gelman at gmail.com> 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.
>
> I like that idea, although I don't know about the name. We also might
> want more features such as access to syntacticly nested functions.
We certainly can't use 'this', because it will break lambda functions
declared inside class methods. So 'self' seems like a reasonable
alternative. But this requires introducing a new keyword, which means
there's the likelihood of breaking existing code that happens to use an
identifier called 'self'.
It's a good idea, though. It will strengthen D's support for functional
style code.
T
--
Let's eat some disquits while we format the biskettes.
More information about the Digitalmars-d
mailing list