4 ms·
I never liked this approach to recursion, as in google's joke search correction for recursion, because recursion is a form of progressive iteration, not reitera
by posterboy 10y ago
I never liked this approach to recursion, as in google's joke search correction for recursion, because recursion is a form of progressive iteration, not reiteration.
- YeGoblynQueenne 10y agoRecursion is frequently used as progressive iteration, but it can go further than that. Typical example, a factorial function, in Erlang: factorial(N) -> factorial(N,1). factorial(0, F) -> F; factorial(N, F) -> factorial(N-1, N*F). It's strange to read that as iteration. Instead it feels natural to describe it as composition from parts that are of the same kind as the whole.
- posterboy 10y agoof course that is some kind of iteration because tail recursion is isomorphic to loops and that N-1 sure looks like a while(--N)
- YeGoblynQueenne 10y agoI'm not sure I know what "isomorphic" means in this context. For sure, (tail) recursion places a pointer to a function on the stack while a loop is a conditional jump. They're not the same thing. I think the similarity between n-1 and --n is a red herring, here.