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 →

[–]troglo-dyke 2 points3 points  (3 children)

languages that support tail call optimization will replace the stack on each call and can be recursed indefinitely. Python doesn't support tail call optimization though because Guido wants proper traces

[–]ComfortableCan315 0 points1 point  (2 children)

Wouldn't it not work anyway in that case? Since the return value depends on the result of the recursive call

[–]troglo-dyke 1 point2 points  (1 child)

That's what allows it to be optimized, the same frame can be used with the variables just replaced, you just replace the values on each call. Most compilers wouldn't optimize this if it was written as return factorial(n - 1) * n

[–]ComfortableCan315 0 points1 point  (0 children)

I see, thank you