[plt-scheme] guido on tail recursion

From: Eli Barzilay (eli at barzilay.org)
Date: Fri Apr 24 20:53:50 EDT 2009

On Apr 24, Jordan Johnson wrote:
> 
> 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.

Yes -- and that's not surprising when it's coming from someone who
didn't internalize the benefit of general tail calls: such people
usually think that this is just some overly sophisticated way to do
simple loops, which are more "understandable" with state...  I think
that Shriram's automaton thing is a good demonstration of what you can
get with tail calls, but the problem there is that it's buried in some
of that "macro" stuff which clearly only crazy people use.

In any case, I'm still waiting for some non-tco way to do the piece of
code that I showed...  The best thing I have so far is something based
on what Nadeem wrote (this is pseudo code, for the obvious reasons):

  function read_loop() {
    var sema = new semaphore(0);
    while (true) {
      print("Say something");
      readline(function(line) {
                 print("you said %s", line);
                 semaphore_post(sema);
               });
      semaphore_wait_and_yield_for_gui(sema);
    }
  }

which relies now on state, on a semaphore, and on a synchornizing
primitive that cooperates with the gui -- and all of this looks to me
like asking for trouble.

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


Posted on the users mailing list.