On Mon, Oct 13, 2008 at 9:27 PM, David-Sarah Hopwood <[EMAIL PROTECTED]> wrote: > MarkM is right that it just falls out of the natural tail-recursive > encoding of a for loop. I got the above expansion wrong by trying to do > it imperatively, which was silly -- the tail-recursive expansion is much > simpler: > > for (let i = initExpr; condExpr; updateExpr) { body } > ==> > { let ($loop = lambda(i) { > if (condExpr) { > { body } (updateExpr); $loop(i); > } > }) { $loop(initExpr); } }
Close. The problem is that updateExpr modifies the same i that's in scope in body, so any closure mentioning i in body captures an i that's modified by the update expression. -- Cheers, --MarkM _______________________________________________ Es-discuss mailing list Es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss