[plt-scheme] Re: Puzzle about amb and memory
On Mon, Mar 31, 2008 at 1:36 PM, Danny Yoo <dyoo at cs.wpi.edu> wrote:
> > I've isolated and resolved a problem in my project. But I don't quite
> > understand why the problem existed!
> >
> > I've distilled what I ran into. I've been using Will Farr's excellent
> > amb.plt PLaneT library to write nondeterministic programs. Here's a
> > small program that demonstrates the issue.
Well, your post encouraged me to refresh my memory on amb and look at
the implementation in the planet library.
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.
test-1 creates one choice point continuation for the entire list of
numbers. Each time a choice fails, it pops back to the same choice
point and tries it again with the next thing in the list.
On the other hand, test-2 uses recursion to create a separate choice
point for each number in the list.
--Mark