[plt-scheme] guido on tail recursion

From: Eli Barzilay (eli at barzilay.org)
Date: Fri Apr 24 16:59:01 EDT 2009

On Apr 24, Nadeem Abdul Hamid wrote:
> Hmm... I see what you mean about the TCO. In Python, one could write:
> def readline(func):
>      '''readline : (string -> a) -> a'''
>      func(raw_input())
> def loop():
>      def callback(line):
>          print "you said %s" % line
>          loop()
>      print "Say something"
>      readline(callback)
> And it definitely doesn't optimize because if you type EOF at some  
> point you get a big long stack trace... talk about turtles all the way  
> down!


> However, the natural imperative way to test such a readline in Python  
> would seem to me to be something like:
> def imp_loop():
>      while True:
>          print "Say something"
>          readline(lambda line: void_print("you said %s" % line))
> No?

No -- the `readline' call returns immediately (in my case, control
goes back to the gui) -- so the above would spin fast starting new
reads instead of waiting for the previous one finishes.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.