[parenscript-devel] Why is there a WITH clause in my loop?

Daniel Gackle danielgackle at gmail.com
Sat Jan 29 01:43:30 UTC 2011


I'm running to this WITH clause in a number of places, but can't see
the (potential) bug you describe in any of them. Can you provide an
example of this bug (that necessitates the WITH)? I don't get it yet.

Daniel


2010/12/10 Vladimir Sedach <vsedach at gmail.com>

> The WITH clause is there to make sure that lambdas capture a fresh
> binding of loop-local variables per iteration (otherwise they'd all
> share the same binding which would get incremented on every loop
> iteration).
>
> I'm guessing the reason your code doesn't run across this bug is that
> the lambda that captures time gets called once per iteration and
> discarded.
>
> Vladimir
>
> 2010/12/7 Daniel Gackle <danielgackle at gmail.com>:
> > Here's a really strange one.
> > We have a form like the following. I've stripped it down for brevity, so
> it
> > looks weird:
> > (loop :for time :from time1 :below time2 :do
> >   (when (foo
> >          (λ ()
> >            (bar
> >             (λ () (blah)) time))
> >          time)
> >     (break)))
> > It used to generate this:
> > for (var time = time1; time < time2; time += 1) {
> >     if (foo(function () {
> >         return barr(function () {
> >             return blah();
> >         }, time);
> >     }, time)) {
> >         break;
> >     };
> > };
> > But now it generates this:
> > for (var time = time1; time < time2; time += 1) {
> >     with ({ time : time }) {
> >         if (foo(function () {
> >             return bar(function () {
> >                 return blah();
> >             }, time);
> >         }, time)) {
> >             break;
> >         };
> >     };
> > };
> > That is one weird WITH clause in there! No doubt it has something
> > to do with lexical scoping magic going on under the hood. But
> > I definitely don't want it in a performance-critical loop.
> > Daniel
> > _______________________________________________
> > parenscript-devel mailing list
> > parenscript-devel at common-lisp.net
> > http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
> >
> >
>
> _______________________________________________
> parenscript-devel mailing list
> parenscript-devel at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/parenscript-devel/attachments/20110128/0403dca8/attachment.html>


More information about the parenscript-devel mailing list