return when desugaring to closures

Yuh-Ruey Chen maian330 at gmail.com
Sun Oct 12 14:19:47 PDT 2008


David-Sarah Hopwood wrote:
> Yuh-Ruey Chen wrote:
> > Now that I think about it, would it truly be necessary for lambda to
> > create an implicit block scope in the first place?
>
> It's not strictly necessary, but it's quite ugly not to. We are intending
> to restrict 'eval' precisely to remove the ability to inject bindings
> into the surrounding scope (although 'eval' is worse because the scoping
> it creates isn't statically analysable).
>
> > |lambda() return 10|
> > would not require such a block scope. Why not have the block scope only
> > created if there are curly brackets? That would follow the precedent set
> > by the rest of the language with regards to block scope
>
> No, that would be entirely inconsistent with the rest of the language:
>
>   { while (...) let x = ...; }
>
> is equivalent to
>
>   { while (...) { let x = ...; } }
>
> not
>
>   { let x; while (...) { x = ...; } }
>   

I was under the impression that such statements should be disallowed,
following the example of JS1.8. In JS1.8 (Fx3), the following are all
syntax errors:

while (...) let x = ...;
do let x = ...; while (...);
if (...) let x = ...;
for (...) let x = ...;

Actually, this might also apply to JS1.7, but I don't have a copy of Fx2
handy.


More information about the Es-discuss mailing list