[iterate-devel] Inaccurate *env* for Macroexpansions

Russ Tyndall russ at acceleration.net
Wed May 20 19:14:31 UTC 2009


Howdy List,


I was having problems when using iterate with the arnesi call/cc
codewalker, because variables bound by iterate were not in the
environment of any macros in an iterate body form.  The codewalker
therefore gets that foo is an unbound variable in the iter clause
below. 

To mitigate this, I patched iterate to update the *env*
variable to reflect any bindings that iterate is going to make (in
sbcl only ATM).  Pulling some code from (bsd licenced)
http://common-lisp.net/project/bese/repos/arnesi_dev/src/lexenv.lisp,
I could probably write an implementation of the two methods I added in
all the arnesi supported environments (lispworks /clisp /allegro
/cmucl), but I have no way of testing these, so for now I stuck with a
tested implementation for sbcl.

The semantics of this are fairly straightforward, in that any variable
declared textually before a macro call will appear as a lexical
variable in the environment passed to the macroexpansion.

(loop for foo upfrom 0
      while (= foo 0)
      collect (funcall (lambda ()
                (arnesi:with-call/cc
                  foo))))
=> (0)

(iter (for foo upfrom 0)
      (while (= foo 0))
      (collect (funcall (lambda ()
                 (arnesi:with-call/cc
                   foo)))))

=> Before my patch this throws unbound variable foo exception /
   lexical environment is empty

   After my patch this "correctly" returns (0)


Cheers,
Russ







-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: environment-update.patch
URL: <https://mailman.common-lisp.net/pipermail/iterate-devel/attachments/20090520/02953365/attachment.ksh>


More information about the iterate-devel mailing list