On Thu, 26 Jan 2012, Brent Hilpert wrote:
From the 3 explanations (Conner,Assumpcao,Mouse) I
have seen so far in this
discussion, a "closure" appears to be the functional-programming
terminology/equivalent for what in OOP would be an "instance of an object".
An instance of an object provides the code (methods) and configuration and
state (private properties) accessed via a single reference (handle).
They have some similarities, but are not the same:
Closures are callable, (most) object instances are not.
Closures have a single entry point, (most) object instances can have
multiple methods called on them.
You can't directly access the data inside the closure from outside, so
there is no 'public' or 'protected' data in a closure.
Closures don't support destructor methods.
Closures don't have a class, i.e. you can't introspect the closure to
determine what 'sort' of closure it is, whereas most object systems allow
you to determine the class of an object instance.
One way of looking at it is that, while closures and object instances are
both code plus encapsulated data, they approach it from different ends: an
object instance smells like a data structure but also has associated code,
whereas a closure smells like a function but also has associated data.
Alexey