[Openmcl-devel] Capturing the lexical value for a special variable

Scott L. Burson Scott at sympoiesis.com
Tue Nov 30 18:34:35 PST 2010


On Tue, Nov 30, 2010 at 5:38 PM, David L. Rager <ragerdl at cs.utexas.edu>wrote:

> Hello CCL-Devel,
>
> Is there a way to force a lambda to capture the lexical value for a
> special variable?  I'd like the following to print "7" instead of "0":
>
> (defvar *v* 0)
>
> (defun bar ()
>  (let ((*v* 7))
>   (ccl:process-run-function
>    "test thread"
>    (lambda () (let ((*v* *v*))
>                 (print *v*))))))
>

A special variable doesn't have a lexical value.  Why not just do this?

(defun bar ()
 (let* ((*v* 7)
        (v *v*))
  (ccl:process-run-function
   "test thread"
   (lambda () (let ((*v* v))
                (print *v*))))))

This is assuming you have some reason to want *v* to be bound in the thread.

-- Scott
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20101130/04ef513d/attachment.htm>


More information about the Openmcl-devel mailing list