For Loop Desugaring (was: return when desugaring to closures)

Brendan Eich brendan at
Tue Oct 14 09:34:06 PDT 2008

On Oct 14, 2008, at 7:17 AM, David-Sarah Hopwood wrote:

> This is subject to the criticism that the loop variable(s) are
> implicitly mutable in the update expression (only), when they were
> declared it to be const.

My point was simpler: sometimes it is handy to write for (const x...)  
and have no fresh binding for x, even though the loop iterates. It's a  
corner case that falls out of parsing var x and const x using the same  
top-down procedure, so not rejecting const where var is allowed. It  
arguably simplifies both implementation and user modeling of the  

We could certainly reject for (const ...; ...; ...) loops if we saw  
this as an anti-use-case.

> No such criticism would apply to 'for each (const ...', though.

Right -- this is pure win.


More information about the Es-discuss mailing list