Editing Recursion
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 79: | Line 79: | ||
== Tail call optimization == | == Tail call optimization == | ||
There is a caveat with recursive programs: Each function call takes up stack space. The deeper you | There is a caveat with recursive programs: Each function call takes up stack space. The deeper you recursive, the more likely you are to run out of stack space and crash your program. This makes recursion useless in most programming languages. | ||
However there is a compromise: If a return in a function is just a call to another function then that return call is a 'tail call'. Languages that implement tail call optimization will re-use the current function call's stack for the function you're calling, solving the issue of stack space. | However there is a compromise: If a return in a function is just a call to another function then that return call is a 'tail call'. Languages that implement tail call optimization will re-use the current function call's stack for the function you're calling, solving the issue of stack space. |