Paul Rubin wrote:
> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>>> Not tail calls, in general, no.
>> Sorry, how does that work? You're suggesting that there is an algorithm
>> which the compiler could follow to optimize away tail-recursion, but human
>> beings can't follow the same algorithm?
>>
>> Now I'm confused.
> 
> The usual compiler method is to translate the code into
> continuation-passing style and thereby gain tail-recursion
> optimization automagically.  

There's no need to go into CPS just to optimise tail-recursion.  After all, 
compilers were optimising tail-calls decades before Appel's work on SML/NJ.

Converting tail-recursion to iteration is trivial, and perfectly reasonable for 
a human to do by hand.  You add an outer "while True"-loop, the recursive call 
becomes a tuple assignment, and other code paths end with a break out of the 
loop.  Completely mechanical and the resulting code doesn't even look that bad.

Like Steven said, tail-call optimisation is not necessary as you can always 
hand-optimise it yourself.

- Anders

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to