[plt-scheme] call/ec tail calls

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Nov 20 17:42:26 EST 2003

At Thu, 20 Nov 2003 17:28:07 -0500, David Van Horn wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> Matthew Flatt wrote:
> > For me, the following expression uses all available memory:
> > 
> >  (let loop ([x 0]) (call/ec loop))
> 
> Using call/cc here will exhaust all available memory too.

Ok, good point. But that's a known space-safety bug in MzScheme, and
not the way `call/cc' is supposed to work. (The bug: although "x" isn't
referenced in the body of the loop, it's still captured by the
continuation.)

This expression's evaluation is bounded, even in MzScheme:

  (let loop ([x 0]) (if (number? x) (call/cc loop) (loop 0)))

And this one's isn't:

  (let loop ([x 0]) (if (number? x) (call/ec loop) (loop 0)))


Matthew



Posted on the users mailing list.