Steve Yegge mentioned it in a blog post and I have no idea what it means, could someone fill me in?
Is it the same thing as tail call optimization?
Steve Yegge mentioned it in a blog post and I have no idea what it means, could someone fill me in?
Is it the same thing as tail call optimization?
from here:
from Wikipedia:
Tail call elimination is an optimization that saves stack space. It replaces a function call with a goto. Tail recursion elimination is the same thing, but with the added constraint that the function is calling itself.
Basically, if the very last thing a function
A
does isreturn A(params...)
then you can eliminate the allocation of a stack frame and instead set the appropriate registers and jump directly into the body of the function.Consider an (imaginary) calling convention that passes all parameters on the stack and returns the value in some register.
Some function could compile down to (in an imaginary assembly language):
Whatever the above actually does, it takes up a whole new stack frame for each call to function. However, since nothing occurs after the tail call to function except a return we can safely optimize that case away.
Resulting in:
The end result is an equivalent function that saves a lot of stack space, especially for inputs that result in a large number of recursive calls.
There's a lot of imagination required in my answer, but I think you can get the idea.