← Back to context

Comment by toast0

10 hours ago

> I've never really understood the desire for tail-recursive versions of iterative algorithms, except for a prior commitment to functional programming.

Tail-recursion and iteration are broadly equivalent right? So picking one over the other is a matter of style and capability.

You can't use iteration if your language isn't capable of it, but no worries, you can use tail recursion.

Similarly, you can't use tail recursion if your language isn't capable of it, but no worries, you can use iteration, at least for iterative tail recursion. Otoh, there are uses of tail call elimination that aren't recursion (or aren't direct recursion) ... that can get akward if your language can't manage it.