[plt-scheme] call/cc and space

From: David Van Horn (dvanhorn at cs.uvm.edu)
Date: Wed Jun 15 16:44:49 EDT 2005

The recent mention of space safety made me revisit R5RS.  Is my understanding 
correct in that the following should use a bounded amount of memory?

(let loop () (call/cc (lambda (k) (loop))))

R5RS requires call/cc to apply it's argument in a tail position, and the call 
to loop is in a tail position within that procedure.  For the same reason, the 
following should run in constant space (and does):

(let loop () (apply loop '()))

The callcc example grows in MzScheme, although not in Petite Chez.  It also 
doesn't seem to be an instance of this known problem:

(let loop ([x 0]) (call/cc loop))

The problem here being that although "x" isn't referenced in the body of the 
loop, it's still captured by the continuation.


Posted on the users mailing list.