[plt-scheme] problem with amb macros

From: Jens Axel Soegaard (jensaxel at soegaard.net)
Date: Sun Dec 14 13:11:01 EST 2008

Hi Sigrid,

> please excuse my question as it's not about PLT-scheme specific  - I'm a
> complete autodidact studying on my own, trying to solve the SICP
> exercises, and I think this group is very helpful and instructive :-)
> I want to solve the amb exercises in SICP not always using the custom
> amb evaluator from the book, but one of the existing macros (as an
> exercise to employ these macros "in the real world").
> However, with both the amb macro from the Dorai Sitaram book and one
> taken from http://community.schemewiki.org/?amb, I do not get the
> expected behavior when I call (amb) again to get the residual alternatives.
> E.g. in exercise 4.45, there should be 5 alternatives, but I get "amb
> tree exhausted" already when I call (amb) after the first try.
> In general it seems the failure continuations are stored correctly in
> the macros - simple cases like
> 1) (amb 1 2) -> 1
> 2) (amb) -> 2
> work as expected, but for the more complicated cases as the
> language-parsing or the puzzles (e.g., exercise 4.43 in the
> "more-than-one-solution" version) it seems that the macros are not
> really equivalent of the SICP amb evaluator... Is this possible?

Without actually testing the macro, I'd say the intention
of the implementation of http://community.schemewiki.org/?amb
is that you can use with SICP. However, it might be that
solutions are generated in a different order than shown in

Do you have a concrete example, that shows where you get
results that differ from your expectation? Can you
perhaps show us what your code for 4.45 looks like?

Jens Axel Søgaard

Posted on the users mailing list.