proper tail calls

Brendan Eich brendan at mozilla.org
Mon Jan 21 12:35:33 PST 2008


On Jan 21, 2008, at 9:59 AM, Erik Arvidsson wrote:

> I think we can all agree on that having explicit tail calls at compile
> time enforces all runtimes to have proper tail calls?

Yes, if we agree on explicit tail call syntax, and if you mean by "at  
compile time enforces" that explicit tail call syntax used in a non- 
tail position results in a compile-time error.

Just to recap a bit:

The standing proposal at http://wiki.ecmascript.org/doku.php? 
id=proposals:proper_tail_calls (which is not a spec, not bug-fixed  
against the rest of the proposed language, but still the accepted  
proposal of long standing) is for implicit proper tail calls. Many  
still favor this. The ticket at http://bugs.ecmascript.org/ticket/323  
proposes explicit syntax, but it is not clear to me that this will be  
accepted.

I think we want something like what Jon Zeppieri proposed in the  
ticket, an explicit "tail call here or error, please" assertion or  
annotation by the programmer, useful to readers as well. This is good  
no matter what the spec says about implicit vs. explicit PTC. In the  
explicit case of course this assertion is expressed directly by the  
PTC syntax -- no need for two ways to say the same thing, or for  
implicit tail calls to be asserted when the programmer could have  
been explicit in how the call itself was written.

Another point of contention is statement vs. expression explicit  
syntax, but I think it would be wrong to have expression closures,  
but not to consider the calls to g and h as proper tail calls in:

   function f(a, b, c) a ? g(b) : h(c);

With explicit syntax, we have to argue about the keyword. My  
enthusiasm for explicit syntax using a "goto" operator is not shared  
by folks who still see disdain and horror among their colleagues in  
reaction to this word. Dave Herman wrote me recently that it might as  
well be spelled "donttouchme" (I was going to guess something  
unprintable ;-).

The concern waldemar raised about debugger-driver confusion due to  
implicit tail calls was thrashed in that lambda-the-ultimate thread I  
cited, and elsewhere. I personally don't think it is a decisive  
argument for explicit syntax, but it adds some weight.

So the axes of disagreement seem to me to be:

1. explicit vs. implicit,
2. whether to have a tail annotation if implicit,
3. statement vs. expression if explicit, and
4. whether explicit is required for debug-ability.

Your point that IF we agree on explicit syntax for PTCs, THEN  
conforming implementations must check at compile time is *probably*  
not controversial, provided the check is purely for tail call  
syntactic position. Conversions (implicit and hardcoded among the  
built-in types representing and wrapping primitives) that might  
defeat PTC may not be evident until runtime, where the result would  
be a TypeError or possibly a new Error subtype.

/be



More information about the Es4-discuss mailing list