proper tail calls

Chris Pine chrispi at
Thu Jan 24 07:03:19 PST 2008

Anton van Straaten wrote:
> In functional languages, proper tail calls are something that just 
> happen automatically (to varying degrees depending on the language), and 
> programmers don't need to think about them most of the time, if at all.

Because of the language semantics, not the implicit/explicit issue.

> If an annotation is required to achieve proper tail calls, it means that 
> you have to be aware of when you're relying on a tail call, and remember 
> to use the annotation, or you'll have runtime problems when you 
> implicitly rely on tail call behavior that's not there.

But this is the case anyway:  you have to be aware of when you're 
relying on a tail call that might not actually be a tail call.

> Like most 
> runtime problems, this could happen in some circumstances but not 
> others, e.g. after your program is deployed, but not in testing.

I agree that failing earlier is better than later.

> At the same time, you can't use the annotation in the wrong place, or 
> you'll also get an error.

Well, as you point out, if you are relying on a tail call when you 
aren't getting one, you *already* have an error.  The question is: 
would you rather fail early or later?  As I said, I agree with you: 
failing early is better.  :)

> So you have two additional classes of error that don't exist in 
> languages with implicit tail calls, and it requires more knowledge and 
> care to use tail calls than it does in languages where they are implicit.

It *does* require more knowledge and care to depend on tail call 
semantics in ES4 than in other languages.  This has nothing to do with 
implicit vs explicit.

The *problem* is not implicit vs explicit.  The problem is the language 
semantics making tail calls not obvious.

> I also find it a bit ironic that errors that result from forgetting to 
> use the tail annotation are the same general class of errors that the 
> annotation is ostensibly intended to guard against: cases where a tail 
> call is expected, but doesn't happen.

:P  You could make the same argument about any kind of error checking, 
couldn't you?  Finding errors earlier is better than later.


More information about the Es4-discuss mailing list