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

Taoufik Dachraoui taoufik.dachraoui at wanadoo.fr
Thu Oct 22 09:51:53 PDT 2009


On Oct 22, 2009, at 6:36 PM, Jon S. Anthony wrote:

>
>
> Also, note the :initial-bindings parameter to process-run-function.
Ok, now I learn that there :initial-bindings, thanks.
But still, the behavior was totally unexpected for me for the
reasons I tried to explain in my earlier post.

Please look again at my post, and tell me what is wrong with my
reasoning.

Thanks

Taoufik

> This enables you to achieve the sort of thing you seem to want.
>
> One other thing, I strongly suggest you adopt (in all cases) the idiom
> of naming top level specials (definitely things in def(var|parameter))
> with '*' bookends:
>
> (defvar *y* 1)
>
> You will be a happier camper...
>
> /Jon
>
>
> On Thu, 2009-10-22 at 12:08 -0400, 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.
>>
>> "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.
>> _______________________________________________
>> Openmcl-devel mailing list
>> Openmcl-devel at clozure.com
>> http://clozure.com/mailman/listinfo/openmcl-devel
>
>






More information about the Openmcl-devel mailing list