[Openmcl-devel] process-run-function and "dynamic vs lexical"

Daniel Weinreb dlw at itasoftware.com
Thu Oct 22 13:26:16 PDT 2009



Taoufik Dachraoui wrote:
>
>
> ? (defvar x 1) ; x is special
> X
> ? (let ((x 1))       ; without declaring x special it is special 
> because of defvar (lost control)
>      (let ((x 2))    ; so where in the specs that says (defvar name init) 
>        (+ x x)))     ; must treat name as special everywhere even if it is
> 4               ; used in a let block, where let is supposed to create
>             ; a new lexical variable binding (not special unless 
> declared so)
No, that's not the Common Lisp language.  If x is globally
declared special, and then you do a let naming x as a
variable, let does a dynamic binding operation.
>
>
> Again look at this example of a closure:
>
> (let ((x 1)) (defun foo (y) (+ x y)))
>
> It is obvious that if x is defvar'ed then the code will not behave as 
> the programmer
> intention.
That depends on what the programmer did, in fact, intend!

But if what you're saying is that this form does different
things depending on whether a global special declaration
has been established (as "defvar" does), that's right, it does.
> This closure definition is legitimate, but the programmer can use a symbol
> name that is defvar'ed without him knowing.
Yes, a programmer could be fooled by not being
aware that x has been declared special.

That's why the *x* convention is used.

Now, whether Lisp SHOULD work this way is a separate
discussion, but that's how Common Lisp is defined.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20091022/e512e62b/attachment.htm>


More information about the Openmcl-devel mailing list