function rec(x, y, z) {
if (something(z)) {
return rec(x, y, z-1);
}
return 1;
}
Now you need to add 1 to the result. function rec(x, y, z) {
if (something(z)) {
return rec(x, y, z-1) + 1;
}
return 1;
}
Ups, now it fails with stack overflow for big z values. Hope you have good unit tests to catch this.To avoid this problem whenever you modify a possibly recursive function in a language with transparent TCO - you have to look through the code to see if it's using TCO. This is wasted time. And it can be non-trivial if you have recursive functions calling each other and other funny stuff.
If instead the language required special syntax for TCO:
function rec(x, y, z) {
if (something(z)) {
return TAIL_CALL rec(x, y, z-1) + 1;
}
return 1;
}
This would be a compilation error cause it's not a tail call contrary to the declaration.What is the downside to requiring special syntax?