return when desugaring to closures

Brendan Eich brendan at
Thu Aug 21 20:30:03 PDT 2008

On Aug 21, 2008, at 7:26 PM, Peter Michaux wrote:

> It works in practice as context of syntax sometime matters.

Context matters in many ways in JS and other languages.

> This is definitely an example of the same syntax having semantically
> different meaning (actually opposite meanings)

The syntax is not the same because of the left-hand side of  
assignment (=) vs. right. Mutation in JS is a concern; you have to  
know whether you're assigning or using a variable; you have to pay  
attention to context.

> which was an objection
> to the use of return in an let statement if a let statement desugars
> to a function-expression call.

I anticipated this when I wrote in an earlier reply:

"Different semantics should have distinct syntax; similarity or
symmetry may motivate reuse of syntactic forms or ideas. Here, there
is no function to return y from, to be assigned to z. You could say
"let desugars", but it doesn't say what it means."

You are proposing the *same* semantics for different syntax (let vs.  
function expression that's called right away). Destructuring patterns  
use the same (or similar, in the case of the object shorthand) syntax  
for related (complementary, symmetric about =) semantics. See the  

That 'return' is the common syntax inside your let-as-lambda-call is  
not the source of similarity, since the outer syntax (let vs.  
function) is dissimilar. The cognitive load comes from the question:  
"where does return go?", since it is a control flow break. The  
Smalltalk page I linked to earlier talks about this.

Another example in favor of similar syntax for similar or related use- 
cases: JS uses function forms in expressions and definitions. The  
contexts and effects differ, but the similarity motivates syntax re-use.

Not so the case with the same (not similar, same -- desugaring)  
semantics for your different outer syntaxes, especially when the cost  
is loss of pellucid return, break, continue, plus the bigger loss of  
purely lexical scope, which by contrast let in JS1.7 provides.


More information about the Es-discuss mailing list