[plt-scheme] guido on tail recursion

From: Jordan Johnson (jmj at fellowhuman.com)
Date: Fri Apr 24 20:17:15 EDT 2009

On Apr 24, 2009, at 1:31 PM, Eli Barzilay wrote:
> Yes.  I should also have added that control might go through several
> pieces of code, and most such pieces of code will do the "obvious
> thing" and end with tail calls -- so things just sort themselves out.
> (I remember that Joe Marshall phrased this nicely at some point, I
> don't remember the sentence though.)

Well, all this points up a chasm between the Schemers' terminology  
and Guido's: in his article he consistently used "TRE" / "tail  
recursion", while here the conversation is about "TCO" and tail call  
elimination.  Sounds like he's just focused on that one special case.

jmj

>
> On Apr 24, Matthias Felleisen wrote:
>>
>> I think Eli meant to add that the call to the callback is in TP and
>> that the call to loop in the callback is in TP and, by the TCO
>> guarantee for Scheme, all of this (well-designed) code becomes a loop
>> (from the perspective of space consumption) on the target machine --
>> Matthias
>>
>> On Apr 24, 2009, at 3:57 PM, Eli Barzilay wrote:
>>
>>> Here's a piece of code that I'm using now -- it's some gui thing,  
>>> and
>>> for technical reasons, I'm implementing a `read-line' method that
>>> reads a line from the gui somehow.  Since the gui is on a single
>>> thread, I made `read-line' get a callback, which is called on the  
>>> line
>>> when it has been read.  To play with my code I wrote a loop that  
>>> reads
>>> lines in a loop:
>>>
>>>          (let loop ()
>>>            (output "Say something")
>>>            (read-line (lambda (line)
>>>                         (output (format "You said: ~a" line))
>>>                         (loop))))
>>>
>>> The thing is that the loop goes through the callback, so it doesn't
>>> translate to a simple (imperative) loop.  Is there a way to do  
>>> this in
>>> python?
>>>
>>> (Looks like it shouldn't be hard, but I can't think of anything.  It
>>> might be that I'm blinded by scheme, or it might be the result of
>>> sleep deprivation...)
>
> -- 
>           ((lambda (x) (x x)) (lambda (x) (x x)))          Eli  
> Barzilay:
>                   http://www.barzilay.org/                 Maze is  
> Life!
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.