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

Daniel Weinreb dlw at itasoftware.com
Thu Oct 22 17:58:55 UTC 2009


Taoufik,

Just to make sure this was clear, the difference
between the two examples isn't whether funcall
per se is being used; the difference is what thread
the closure is run in.  The first example runs the
closure in another process.  The symbol f
is intepreted as a dynamic variable, and it sees
the global value, rather than 3, because the value 3
is specific to the main thread, and does not apply
to the newly-created thread.  Bindings of dynamic
varaibles apply only to the thread in which they
were bound.

I agree strongly that you'll have a much easier time
if you follow the convention of surrounding the
names of symbols that are declared special with
*'s (or +'s for constants).

-- Dan

Taoufik Dachraoui wrote:
> I run the follwoing tests (1, 2 and 3) and cannot understand why  
> process-run-function
> seems to ignore the definition of the variable y  within the scope of  
> the let
>
> ? (defvar y 1)
> Y
>
> <1>>>>> First using process-run-function
>
> ? (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
> ?
>
> <2>>>>> AND using funcall
>
> ? (let ((x 2) (y 3))
>      (labels ((f () (format t "x=~A y=~A~%" x y)))
>         (funcall #'f)))
> x=2 y=3
> NIL
> ?
>
> <3>>>>  AND last
>
> ? (let ((x 2) (y 3)) (format t "x=~A y=~A~%" x y))
> x=2 y=3
> NIL
> ?
>
>
> The last 2 tests are obviously what I expected but I do not understand
> why when using process-run-function the y value within the new process
> is 1 and not 3. How to explain this, it is really confusing for me?
>
> Taoufik
>
>
>
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel
>   



More information about the Openmcl-devel mailing list