return when desugaring to closures

Brendan Eich brendan at mozilla.com
Mon Oct 13 15:09:42 PDT 2008


On Oct 12, 2008, at 1:39 PM, David-Sarah Hopwood wrote:

>> |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 in any let proposal -- specifically, grammar -- that I know of.  
See my last post.

In the case of for (let x...) ... this seems like a bug, cited in last  
message, here it is again:

https://bugzilla.mozilla.org/show_bug.cgi?id=449811


> not
>
>  { let x; while (...) { x = ...; } }

Rather, the proposed let declaration grammar requires that let be a  
direct child of a block, function body, for-loop head, or top-level  
program -- anywhere else and it's a syntax error.


> I don't think that such an "unscoped" lambda provides enough (if any)
> value to justify its complexity.

I agree, "unscoped" lambda is not worth specifying as such, and begs  
questions about what scope any formal parameters go in (could be the  
block induced by {...} comes back if there are formals, but then  
again, there's no point in talking about the unscoped degenerate  
case). As an optimization, implementations will erase unnecessary  
scopes. But the spec shouldn't worry about this.

/be


More information about the Es-discuss mailing list