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

Taoufik Dachraoui taoufik.dachraoui at wanadoo.fr
Thu Oct 22 09:57:33 PDT 2009

On Oct 22, 2009, at 6:08 PM, Greg Pfeil wrote:

> 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.
Does this pervasiveness is a fatality?

Looking at CLHS the only thing I could see so far is that (DEFVAR name  
establish  name as a dynamic variable. I could not find anything about  
pervasiveness of DEFVAR.

Also, as explained in my previous post, the let block create new  
lexical bindings
and since the y name was not declared special I  do not see why the  
has to complicate things.

Please look again, and pay attention to the name substitutions and try  
to tell me
why my reasoning is wrong.

Kind regards

> "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