4 ms·
> My (admittedly naive) understanding of TCO is that it involves turning tail recursion into a loop This is close, but not the full story. TCO turns tail recu
by crux_ 17y ago
> My (admittedly naive) understanding of TCO is that it involves turning tail recursion into a loop
This is close, but not the full story.
TCO turns tail recursion into a GOTO (well, a goto-with-arguments). In the case of a single function which tail-calls itself, this becomes a loop, but for multiple functions that are mutually recursive, that's not the case.
Note that the issues with the lack of TCO boil down to efficiency: there are ways of faking TCO atop a runtime that does not support it (meaning deeply tail-recursive code will run, rather than overflow the stack), but they come at with a runtime cost.