On Mon, May 27, 2013 at 11:52 PM, Ned Batchelder email@example.com wrote:
On 5/27/2013 9:30 AM, Chris Angelico wrote:
What can tail recursion do that can't be done by reassigning to the function parameters and 'goto' back to the top?
That style can't handle mutually recursive procedures, or the extreme case: a state machine implemented with N functions, each of which calls the next state function at the end. Tail-call elimination isn't simply about noticing recursive calls. It's about noticing that a function ends with a function call, and not burning another stack frame in the process.
Ahh, gotcha. Of course. Mutual recursion would be a bit more of a problem to the compressor, too, though; it'd have to recognize a pattern that spans multiple stack frames.