return when desugaring to closures

Brendan Eich brendan at
Mon Oct 13 17:09:48 PDT 2008

On Oct 13, 2008, at 5:00 PM, Jon Zeppieri wrote:

> On Mon, Oct 13, 2008 at 7:39 PM, Brendan Eich <brendan at>  
> wrote:
>> On Oct 13, 2008, at 4:14 PM, Jon Zeppieri wrote:
>>> Yes, and binding a fresh induction variable on every iteration makes
>>> sense for a 'for-each' loop (as in the bug report you cited), where
>>> the user is not in charge of updating the induction variable by  
>>> means
>>> of explicit assignment.  In a plain 'for' loop, however, it *is*  
>>> magic
>>> if an assignment results in a fresh binding.
>> Why is the assignment operator relevant? The question is the binding
>> scope of i in
>>  for (let i = 0; i < N; i++) ...
> How is scope the issue?  As far as I know, we don't disagree about  
> scope.

Probably we're at cross purposes (I often am ;-) because of the primal  
sin in ECMAScript of specifying scope via object, and closure via  
scope chain capture.

> The assignment I'm referring to, in this example, is the 'i++' part.
> Mark is proposing that this does not mean "increment i by one," but
> rather "rebind i with the value of i+1" -- which is completely
> different and not what the user wrote.

Gotcha -- I agree, this is a problem for a proposal that tries to  
desugar for(;;). Curses.

The user expectation with a closure in a for(var i = 0; i < N; i++)  
loop, that each closure captures i's current value, remains,  
completely parallel to the for (i in o) ... case. Any attempt to solve  
it via let instead of var -- other than by making multiple (blech)  
scope (barf) objects, one per iteration -- must respecify how closures  
work. Hmm.


More information about the Es-discuss mailing list