[Openmcl-devel] process-run-function and "dynamic vs lexical"
greg at clozure.com
Thu Oct 22 16:20:19 EDT 2009
On 22 Oct 2009, at 15:27, Taoufik Dachraoui wrote:
> ? (defvar x 2)
> ? (let ((x 1))
> (flet ((foo () x))
> (let ((x 5)) (+ x (foo)))))
> After defining x using defvar, the let block do not follow the specs;
> in the specs,
> let creates a new variable binding and that binding is lexical unless
> the name
> is declared special.
> Now my question, how come at compile/eval time the foo function was
> lexically bound to the first value of x within the let block (since x
> is the name
> of a new variable binding and it is lexical since there is no special
> for x?).
On the DEFVAR page of CLHS, there's a sample implementation of DEFVAR
that DECLAIMs the name SPECIAL. So there _is_ a special declaration
for X. It's just not a "lexical" declaration, but rather a declaration
in the global environment.
I agree that this is confusing and unpredictable behavior, but it's
behavior that the spec requires and that every CL impl provides. This
is why we have the *X* convention.
More information about the Openmcl-devel