[plt-scheme] tail position

From: Daniel Silva (dansilva at lynx.dac.neu.edu)
Date: Fri Nov 21 05:38:06 EST 2003

If this (f x) is in tail position:

 (define (f x)
   (call-with-escape-continuation
      (lambda (ec)
         (let ([s (void)])
           (set! s (make-string 1000000))
           (collect-garbage)
           (display (current-memory-use))
           (newline)
           (f x)))))

then why isn't this one?

 (define (f x)
   (let ([s (void)])
     (call-with-escape-continuation
       (lambda (ec)
         (set! s (make-string 1000000))
         (collect-garbage)
         (display (current-memory-use))
         (newline)
         (f x)))))

The second example shows a 1MB increase at every iteration, while the
first one does not.

Daniel



Posted on the users mailing list.