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

call/cc and proper tail recursion



   I think the report needs to clarify the tail recursive property of
   call/cc.

I think so also; It should be clarified to NOT require
CALL-WITH-CURRENT-CONTINUATION be tail-recursive.

   Presently nothing is said about the behavior of this
   simple program when it comes to tail recursion:

   (define (foo) (call-with-current-continuation (lambda (k) (foo))))

   In my mind, it should be equivalent to

   (define (foo) (foo))

   Thus call-with-current-continuation does not introduce any new
   continuation frames.  The body of the procedure argument to call/cc
   is evaluated with the SAME continuation as call/cc's continuation.

I don't think such non-terminating programs should be considered
conforming.  We can waste a lot of time getting compilers to properly
optimize (for tail-recursion, etc) such limit cases.

   Some implementations do not conform to this specification, that is they
   run out of space.

That an implementation runs out of space does not prove that
CALL-WITH-CURRENT-CONTINUATION is not tail-recursive!
CALL-WITH-CURRENT-CONTINUATION creates a continuation which can
occcupy storage;  As paragraph 4 in Section 1.1 points out,
Implementations are not required reclaim unused storage (only allowed).
This storage is far more than the amount of the stack consumed with
each recursion.  The implementations which I have seen this example
fail on (MITScheme and SCM) run out of space for the continuations.

To require CALL-WITH-CURRENT-CONTINUATION be tail recursive is penny
wise and pound foolish.