[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Another question about lexical closures
Date: 15 May 1985 0213-PDT
There's a little ambiguity about when two bindings are "the same" and when
they are "different" bindings. If you bind exactly the same lexical variable
(in the same function or other executable form) to exactly the same value
(the values are EQ), at two different times, are the two bindings you get
considered to be the same or different?
The way I think of this is "Two calls to LET produce two different
bindings". So if I read your question right, the answer is "different".
I.e. if you make a lexical closure
in function FOO with X bound to NIL and then make another lexical closure
in function FOO with X bound to NIL, will the X-variables in those two
closures be the same variable (sharing side-effects) or not?
I assume here you mean two calls to FOO, not something like
(LET ((X 5))
(VALUES #'(LAMBDA () X) #'(LAMBDA (Y) (SETQ X Y))))
where the answer is "save variable (sharing side effects)"
is they will be different, that is each time you go into a lambda-binding
you get a "different" binding even if the lexical variable and its value
are the same both times. Am I correct?
(Note the example at the bottom of
page 87 doesn't answer this question since TWO-FUNS is called only once.
Indeed, I think this section could use a bit more exposition and further
examples. I think the manual can't help being a bit of a language
tutorial here, and should abandon the tersness of a reference manual,
even if it ends up repeating the same concept in different ways.
If it got called a second time, with exactly the same args, and the result
SETQ'd to global FUNS2, would (CAR FUNS) and (CAR FUNS2) share their
lexical-closure-variable, i.e. "the binding of the variable X created
on entry to the function TWO-FUNS when it was called with argument 6"
as described at the bottom of the page? That phrasing indicates there
WOULD be sharing, but due to what it says on page 37 top "it depends
on the invocaton during which the reference is made" I think it WOULD NOT
be sharing, i.e. wording on page 87 should really say "... on that particular
entry to the function TWO-FUNS ..." even though in that example it is moot
since TWO-FUNS was called only once in the example.)
That's right. There would be sharing between (CAR FUNS) and (CADR FUNS), and
between (CAR FUNS2) and (CADR FUNS2), but not between the elements of FUNS