Function literals and lambda functions
Simen kjaeraas
simen.kjaras at gmail.com
Sun Mar 6 09:25:29 PST 2011
Russel Winder <russel at russel.org.uk> wrote:
>> That said, the above looks like it should work, and I'm not sure why it
>> doesn't.
>
> Obviously (now :-) because the context requires a delegate not a
> function -- it is just that the error message doesn't say that in terms
> that don't relate to the code they relate to the realization within the
> compiler.
Yeah, but reduce should accept a function, not just a delegate.
> Is this use of the term delegate consistent with the C# idea of
> delegate? It certainly is not consistent with the use in Groovy and
> other dynamic languages.
There's been some discussion of that before, but I cannot remember whence
the term comes. Basically, it it chosen because it's a function pointer
with a context passed alongside it, and that's no different for a
pointer-to-member-function or a closure.
And to illustrate the latter:
The venerable master Qc Na was walking with his student, Anton. Hoping
to prompt the master into a discussion, Anton said "Master, I have heard
that objects are a very good thing - is this true?" Qc Na looked
pityingly at his student and replied, "Foolish pupil - objects are merely
a poor man's closures."
Chastised, Anton took his leave from his master and returned to his cell,
intent on studying closures. He carefully read the entire "Lambda: The
Ultimate..." series of papers and its cousins, and implemented a small
Scheme interpreter with a closure-based object system. He learned much,
and looked forward to informing his master of his progress.
On his next walk with Qc Na, Anton attempted to impress his master by
saying "Master, I have diligently studied the matter, and now understand
that objects are truly a poor man's closures." Qc Na responded by hitting
Anton with his stick, saying "When will you learn? Closures are a poor
man's object." At that moment, Anton became enlightened.
-- Anton van Straaten
--
Simen
More information about the Digitalmars-d
mailing list