by geuis · 16y ago · 0 comments
"So please, do not call all functions where the last function call in your source code is a call to itself, tail recursive. A function is tail recursive, if the last operation is a function call to itself."
It reads to me as "Don't call functions that call themselves last tail recursive. A function is tail recursive if it calls itself last."
That's saying the same thing, if my reading of it is right. His oddly-placed commas don't help.
function foo(n) {
...
return n+foo(n-1);
}
is not tail recursive because the last operation is not the recursive function call, but rather the addition. function bar(n,acc) {
...
return bar(n-1,acc+n);
}
is tail recursive because the last operation is now the recursive function call.