Tail recursion to while iteration in 2 easy steps

random832 at fastmail.us random832 at fastmail.us
Thu Oct 3 10:09:25 EDT 2013


On Wed, Oct 2, 2013, at 17:33, Terry Reedy wrote:
> 5. Conversion of apparent recursion to iteration assumes that the 
> function really is intended to be recursive.  This assumption is the 
> basis for replacing the recursive call with assignment and an implied 
> internal goto. The programmer can determine that this semantic change is 
> correct; the compiler should not assume that. (Because of Python's late 
> name-binding semantics, recursive *intent* is better expressed in Python 
> with iterative syntax than function call syntax. )

Speaking of assumptions, I would almost say that we should make the
assumption that operators (other than the __i family, and
setitem/setattr/etc) are not intended to have visible side effects. This
would open a _huge_ field of potential optimizations - including that
this would no longer be a semantic change (since relying on one of the
operators being allowed to change the binding of fact would no longer be
guaranteed).



More information about the Python-list mailing list