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

Jon S. Anthony j-anthony at comcast.net
Thu Oct 22 09:36:27 PDT 2009


Also, note the :initial-bindings parameter to process-run-function.
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