On Recursion, Continuations and Trampolines
How is tail recursion different from regular recursion? What do continuations
have to do with this, what is CPS, and how do trampolines help? This article
provides an introduction, with code samples in Python and Clojure.
Here's a textbook version of a recursive factorial implementation in Python:
def fact_rec(n):
if n == 0:
return 1
else:
return n * fact_rec(n - 1)
Tail recursion is when the recursive call happens in tail position, meaning
that it is the last thing the function does before retu...
Read more at eli.thegreenplace.net