[parenscript-devel] Inaccurate lexical capture in loop

Daniel Gackle danielgackle at gmail.com
Wed Apr 11 19:03:39 UTC 2012


PS seems to think that the variable named BLOCK is being captured by
the irrelevant lambda and inserts a WITH binding.

   PS> (ps (loop :for i :from 0 :below 5 :do
             (let ((block (elt blocks i)))
               (foo block)
               (lambda () nil))))

   "for (var i = 0; i < 5; i += 1) {
       with ({ block : null }) {
           var block = blocks[i];
           foo(block);
           function () {
               return null;
           };
       };
   };"

This doesn't happen if you take out the lambda:

   PS> (ps (loop :for i :from 0 :below 5 :do
             (let ((block (elt blocks i)))
               (foo block))))

   "for (var i = 0; i < 5; i += 1) {
       var block = blocks[i];
       foo(block);
   };"

... or even if you rename BLOCK to B:

   PS> (ps (loop :for i :from 0 :below 5 :do
             (let ((b (elt blocks i)))
               (foo b)
               (lambda () nil))))

   "for (var i = 0; i < 5; i += 1) {
       var b = blocks[i];
       foo(b);
       function () {
           return null;
       };
   };"

I thought this might be because PS had compiled a different form where
BLOCK was indeed captured by closure in a loop and was remembering
this inappropriately. But that doesn't seem right because the problem
is reproducible on a fresh restart of PS.

Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/parenscript-devel/attachments/20120411/eef30938/attachment.html>


More information about the parenscript-devel mailing list