[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tail recursion (was Re: a (revised) draft of R5RS)

From: Alan Bawden <Alan@lcs.mit.edu>
Subject: tail recursion (was Re: a (revised) draft of R5RS)
Date: Tue, 27 May 1997 16:04:21 -0400

> (Matthias Blume sent a number of examples asking, for each one, if the call
> to `f' should be tail recursive.  As far as I can see, the answer in each
> case is "yes, of course".  I suppose an implementor can be forgiven for
> missing any one of them, but I would expect him or her to fix the problem
> once it was pointed out.)

I would prefer to make things _very_ explicit, because there are a few
tricky cases. For example:

   (call-with-input-file file f)

Intuitively the call to f will not be tail-recursive, because of the
need to close the port upon exit.  But what if there is no need to
ever close a port?!  In an implementation that completely relies on
some form of GC for ports this could actually be implemented.
(close-input-port etc. would simply be no-ops and there would be no
difference between open and closed ports in such an implementation.)

Of course, this is pretty far-fetched.  I am just trying to convince
you not to rely too much an the implementor's intuition when making
such decisions...