lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Thu, Nov 11, 2004 at 02:30:50PM -0200, Roberto Ierusalimschy wrote:

> > Incidentally, that's why closures are called closures, ie. because
> > they capture their environment at the moment the closure is formed.
> > If the environment is kept open, it's not closed.  The foo in your
> > function is still a free variable! :-)
> They capture the variables, not their values. The foo in that function
> is not free at all, it is forever binded to the local variable created
> with the first "local" declaration.

But that's precisely the point.  The purpose of the closure is to turn
an impure function (one that is dependent on its environment) into a
pure function that is dependent only on its arguments --- ie. a pure
function in the sense of the lambda calculus.  That's why it takes a
"snapshot" of the bindings of any free variables it uses, because that
closes off its sensitivity to external changes.

This is why closure is often referred to as "partial application" ---
the implicit external arguments are "applied", leaving the function a
fully pure one with only its explicit arguments remaining to be defined.
It's just like currying over the partial (implicit) arguments.

One can certainly define some sort of partial closure as in this case,
and it definitely has programming uses.  But it's not full closure. :-)

Rich Artym.
Existing media are so disconnected from reality that our policy debates
spin around a fantasy world in which the future looks far too much like
the past.