Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There's no call stack in a tail-recursive function. It's equivalent to a loop.

And that, if you think about it a bit, might help you understand what recursion is, because your current understanding seems a bit off.

The only time you need a "call stack" with recursive calls is if the calls need to ultimately return to the call site and continue executing. It's still recursive.

By contrast, the model in which every function call pushes a return address, whether or not it's really needed, is a kind of mistake that comes from not understanding recursion.



Yes. This is correct, tail call optimized recursion is physically different than other types of recursion. It's much needed syntactic and structural sugar for goto.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: