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

Free variables in a LAMBDA which names a function



Section 5.2 of CLtL point out that there's a distinction between
(LAMBDA ...) as a way of \naming/ a function, and as a function
object.

What are the semantics of a free variable within a LAMBDA which
merely \names/ a function?  For example:

(defun foo (arg)
  ((lambda (x) (+ x arg)) 5))

I would expect:

(setf arg 16)
(foo 3) ==> 8

I'm using a beta test of a Common Lisp which returns 21 as the
result of that (foo 3).  Looking through CLtL, I see nothing that
implies that (lambda ...) in the functional position of a form
has its free variables interpreted lexically, rather than dynamically.

Am I overlooking something?  Is it reasonable to expect (foo 3) to
return 8, or am I depending on coincidence...

[This question arose when trying out the Common Lisp version of
LOOP which GSB passed on to me a few weeks back.  That LOOP
expands into expressions which require that free variables in
initial lambdas be lexically scoped]

- Steve