3 ms·
I suspect a better approach is to make expected tail recursion a language feature, and have the compiler emit an error if the returned expression is not in fact
by barrkel 16y ago
I suspect a better approach is to make expected tail recursion a language feature, and have the compiler emit an error if the returned expression is not in fact valid for a tail call.
Imagine if it were 'treturn' or something.
It's not something that bites people who have been around this mulberry bush before, but I think it can very likely catch problems that novices have, thinking they're writing an O(1) space solution but actually using O(n) stack.
- eru 16y agoOK. But then, even if somebody is using `return', and its tail-recursive, it should be optimized. (`return' should just not raise an error, if it's not tail-recursice.)