proper tail calls

Brendan Eich brendan at
Mon Jan 21 23:05:08 PST 2008

On Jan 21, 2008, at 10:50 PM, Brendan Eich wrote:

>> "return" might be a
>> good choice of syntax if it weren't for the implicit conversion
>> problem.
> It would, indeed: return and yield would both then be low-precedence
> unary operators.

(Low-level grammatical quibble with myself, probably only of interest  
to a few folks:)

Not quite: the comma operator bites (there, I said it). Although in  
js1.7 and 1.8 (firefox2 and 3) we make it an error if you don't  
parenthesize |yield expr| in |foo(yield expr, arg2)|, a statement | 
return expr, expr2| is already defined by a production whose right  
nonterminal is a comma expression (ListExpression in ES4's grammar).

To avoid confusion in argument lists vs. comma expressions, and to  
relieve users from having to over-parenthesize yield and let  
expressions, and expression closures, when they are in an actual  
parameter list or enclosing comma expression, ES4 makes the right  
nonterminal be AssignmentExpression for all of yield expressions, let  
expressions, and expression closures.

This works well enough as far as I can tell, although the js1.7-1.8  
extra error check is more Pythonicly paranoid/pedantic, and we lack  
deep usability data to judge whether it is justified. Savvy hackers  
will overparenthesize where there is the slightest chance of  
confusion, but not excessively (Python requires foo((yield bar)),  
e.g., which is just silly).

Since return may involve a conversion, it's off the table, so this is  
all moot. But it's attractive as a tail operator and some languages  
have used it that way. Again, Anton in that LtU thread:


More information about the Es4-discuss mailing list