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

requiring proper tail recursion





   I would therefore support a strengthening of the R4RS requirement
   for proper tail recursion, with wording somewhat as follows (which
   borrows from John Ramsdell's suggested paragraph):

     Implementations of Scheme are required to be properly
     tail-recursive.  This means implementations must recognize
     syntactically tail-recursive calls, whose result will be
     returned by the procedure whose body contains the
     tail-recursive call.  In effect, implementations must
     arrange for the result of a tail-recursive call to be
     returned directly to the continuation that was passed to
     the procedure that contains the tail-recursive call,
     instead of being returned to that procedure.  This
     allows iteration to be expressed using the ordinary
     procedure-call mechanics, so that special iteration
     constructs are useful only as syntactic sugar.

I find this paragraph difficult to read.  As such, I feel that those
who are less knowledgable will find it opaque.   Might I suggest
something like the following?  the second sentence is still too
unwieldy for a final product, but I think the following version is a
little easier to understand.

     Implementations of Scheme are required to be properly
     tail-recursive.  Any procedure applications appearing in another
     procedure having the property that whatever value is returned by
     the applied procedure will in turn be returned by the procedure in
     which the application appears is said to be in a tail position.
     The important feature of procedure applications in tail position
     is that the stack frame for the calling procedure is unneeded once
     the call has been made.  An implementation is said to be properly
     tail-recursive if it in effect arranges for the result of a
     tail position call to be returned directly to the continuation
     that was passed to the procedure that contains the tail position
     call, instead of being returned to the calling procedure.
     Proper tail-recursion allows iteration to be efficiently
     expressed using ordinary procedure-call mechanics.  Special
     iteration  constructs become useful only as syntactic sugar.
--------------------
Morry Katz
katz@cs.stanford.edu
(415)723-9510 (office)
(415)694-9121 (pager)
--------------------