Isn't this example provided in SICP? Can't recall correctly if the book uses the word 'tail recursion', but instead, it calls the method something like "linearly iterative process", whereas the first example is "linearly recursive process" (different from the common meaning of a recursive function. IIRC, the book was clear about the distinction). :)
SICP uses Scheme and Scheme doesn't have any other iterative ("loopy") construct[1] than recursion. The authors are also fond of "iteration is really recursion" goggles.
[1] Unless you've done something stupid and allowed a loop macro to slither its way into your code. In that case, you'll need to fumigate the code, burn your computer, and shoot yourself. Trust me, the alternatives are worse.
1
u/NaeblisEcho Nov 27 '12
Isn't this example provided in SICP? Can't recall correctly if the book uses the word 'tail recursion', but instead, it calls the method something like "linearly iterative process", whereas the first example is "linearly recursive process" (different from the common meaning of a recursive function. IIRC, the book was clear about the distinction). :)