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

Greg Pfeil greg at clozure.com
Thu Oct 22 16:08:09 UTC 2009


On 22 Oct 2009, at 11:42, Taoufik Dachraoui wrote:

> Just for completeness I include the example:
>
> ? (defvar y 1)
> Y
> ? (let ((x 2) (y 3))
>    (labels ((f () (format t "~%x=~A y=~A~%" x y)))
>      (ccl:process-run-function "test" #'f)))
> #<PROCESS test(3) [Reset] #x8D43546>
> ?
> x=2 y=1
> ?
>
> let creates new variable binding for the names x and y and these
> bindings are lexical unless they are declared special.
...
> Where is my mistake, please note here that I would like to reconcile
> my understanding with what I see while running ccl code.

If you check Ron's guide to specials (http://www.flownet.com/ron/specials.pdf 
), the section "The pervasiveness of DEFVAR" explains what you're  
seeing.

"Because DEFVAR does more than just establish a dynamic binding for X.  
It pervasively declares all references to X and all subsequent  
bindings for X to be dynamic (or special -- same thing). In other  
words, DEFVAR turns its argument (permanently and pervasively) into a  
special variable."

So the Y <= 3 binding is actually for the special variable, but the  
binding of the 3 is thread-local, so your function run in its own  
thread still sees the value 1.



More information about the Openmcl-devel mailing list