[plt-scheme] Re: Puzzle about amb and memory

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Tue Apr 1 13:22:37 EDT 2008

> I think the crux of the problem is that your test-1 creates 7
> continuations, and test-2 creates 70 continuations.  Apparently, 70
> continuations is enough to cause PLT Scheme to segfault, but 7 isn't.


Hi Mark,

But just creating continuations isn't going to exhaust memory, unless 
those continuations can't be garbage collected.  For example:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#lang scheme/base
;; infinite loop through call/cc
(define (inf)
   (define top #f)
   (let/cc k
     (set! top k))
   (let/cc k2
     (top)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

runs perfectly well in bounded space even though it's busily creating 
k2 continuations like mad.


My assumptions right now are that either the recursion either isn't tail, 
or the continuations aren't getting collected.  I've pored at the amb 
source code a bit, but I don't see yet anything wrong with regards to tail 
calls.


Posted on the users mailing list.