Re: A question (confusion) about closure



On Sun, 4 May 2008 08:02:23 -0700 (PDT), "xahlee@xxxxxxxxx"
<xahlee@xxxxxxxxx> wrote:


Still, it troubles me deeply, how could a patently simple explanation,
a simple concept, a penetrating view, be not clearly grasped by a
gaggle of lispers? In this thread, there are 15 messages. Not one
reply, seems to indicate that what i said is correct. Almost half of
them actually pointed out that i was incorrect, and even unhelpful.
I'm greatly troubled by this. To me, this is like going into a bar,
and when the subject of 1+1 comes up, my nonchalant remark of 2
suddently made everybody stare. This can be a terrifying experience.
Like, in a bar you suddenly realized all the people around you are not
humans but aliens. Or, you realized it's a gay bar and you are not
gay. Or, they are all black and you are the only white. Or, you are
standing out like a sole genius.

You _are_ incorrect. Following some factually correct but irrelevant
information about naming conventions, you said:

"If the language hides such global vars from user,
and provide transparent ways when you create or
access them inside your function without the __
prefix, that's closure."


Conceptually, closures create a parameterized instance of a function
by capturing the values of the function's free variables. As a
technical matter, closures were specifically created to address the
problem of "non-local" lexically scoped variables. Globals are free
variables but they are not considered to be "non-local" in the lexical
sense.

There is no technical reason why closures could not also capture
globals (the top-level is a lexical scope after all), but there is a
semantic reason not to. The variables in each lexical scope can be
thought of as out-of-band communication channels for parts of the
program contained within the scope. If all free variables were to be
captured, there would be no way to communicate out-of-band data[*].
Globals, in particular, are considered to be for communication between
different parts of the program, so globals are treated specially and
are not captured by closures.
[*] some people would consider that a Good Thing(tm).

George
--
for email reply remove "/" from address
.