Tail recursion to while iteration in 2 easy steps

Antoon Pardon antoon.pardon at rece.vub.ac.be
Tue Oct 8 05:18:35 EDT 2013


Op 08-10-13 01:50, Steven D'Aprano schreef:
> On Mon, 07 Oct 2013 15:47:26 -0700, Mark Janssen wrote:
> 
>> I challenge you to get
>> down to the machine code in scheme and formally describe how it's doing
>> both.
> 
> For which machine?
> 
> Or are you assuming that there's only one machine code that runs on all 
> computing devices?
> 
> 
> Frankly, asking somebody to *formally* describe a machine code 
> implementation strikes me as confused. Normally formal descriptions are 
> given in terms of abstract operations, often high level operations, 
> sometimes *very* high level, and rarely in terms of low-level "flip this 
> bit, copy this byte" machine code operations. I'm not sure how one would 
> be expected to generate a formal description of a machine code 
> implementation.
> 
> But even putting that aside, even if somebody wrote such a description, 
> it would be reductionism gone mad. What possible light on the problem 
> would be shined by a long, long list of machine code operations, even if 
> written using assembly mnemonics?
> 
> Far more useful would be a high-level description of Scheme's programming 
> model. If names can be rebound on the fly, how does Scheme even tell 
> whether something is a recursive call or not?
> 
> def foo(arg):
>     do stuff here
>     foo(arg-1)  # how does Scheme know that this is the same foo?

It doesn't and it doesn't need to. tail call optimisation is not
limited to recursive functions. All tail calls can be optimised,
recurisive call and others.

-- 
Antoon Pardon





More information about the Python-list mailing list