[plt-scheme] Re: Puzzle about amb and memory
amb subexpressions can't be in tail position. After spawning the
threads you have to monitor them, returning the first value either
one of the produces.
On Apr 1, 2008, at 1:22 PM, Danny Yoo wrote:
>> 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.
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme