Delegates
Bruno Medeiros
brunodomedeiros+spam at com.gmail
Sat Jan 20 02:44:15 PST 2007
Robin Allen wrote:
> I'm trying to figure out delegates. From what I can see, they're intended to be what other languages call closures?
>
Not exactly. Delegates and delegate literals (aka anonymous delegates)
are what other languages, namely functional ones, call lambda expressions.
Closures are an optional language feature of
lambda-expressions/delegate-literals, that allows such literal to
reference variable outside its scope. D implements closures but with
some quirks: if the variables referenced externally are stack allocated,
then when their stack frame life ends, it is invalid to reference such
variables, and consequently use the delegate. (and this happens often)
This problem is never present with LISP for example, because all data is
heap-allocated.
--
Bruno Medeiros - MSc in CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
More information about the Digitalmars-d-learn
mailing list