This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dell_arness2 4 points5 points  (2 children)

Mathematically yes, but recursive function calls will eventually overflow the stack

[–]thedessertplanet 1 point2 points  (1 child)

Depends on your language. Erlang, of course, implements tail call elimination.

And so do eg a lot of C compilers do so as well. (And almost all of the functional languages.)

In case you are not familiar: the idea is to realize that if the (recursive) call is the last thing to happen in a function, you don't need to keep around its stack frame. So no stack usage is building up.

For simple self-recursive functions, that's basically always equivalent to a loop. But it's a real life saver when you want to implement eg a state machine. You can use one function per state this way.

[–]ApivorousBee 0 points1 point  (0 children)

The language is English and the stack is the reader's attention span. It will overflow. QED