lexical for-in/for-of loose end
brendan at mozilla.com
Sat Feb 4 15:17:49 PST 2012
Herby Vojčík wrote:
> It looks to me that all those schemes and desugaring are very
And what you showed isn't complicated? LOL.
What you're sketching is an optimization, one I believe Chez Scheme and
other implementations perform. Indeed any good implementation will
optimize let-bound loop variables to registers and avoid any
per-iteration overhead in the absence of closures.
But what you sketched is nothing like a specification.
A normative specification does not describe non-observables, except in
informative asides (which should be used sparingly). A specification
must simply and clearly state the rules for syntax and semantics.
In particular, the ES6 specification governing the for-let loops we're
discussing needs specific treatment to avoid the notorious var
pigeon-hole problem made observable by closures in the loop body that
capture loop variables. The simplest way to do this is being worked out,
but it will necessarily entail a scope per iteration.
I argue the first iteration's scope must enclose the initialisers for
the for(let;;) head's first of three parts. This is an important detail.
It's not complicated beyond other parts of the spec; it's just detailed.
We have to have consistent for(let;;) semantics, and as the discussion
has evolved (since 2008) we've come to agree on the constraints by which
we reckon "consistent". The constraints require a specific solution, in
my view: first iteration's scope covers iniitalizers, and
observably-distinct let scopes for each iteration.
More information about the es-discuss