[racket] handy trick for "amb-collect" desired

From: Thomas Chust (chust at web.de)
Date: Sun Sep 12 17:01:03 EDT 2010

2010/9/12 Will M. Farr <wmfarr at gmail.com>:
> [...]
> amb is a macro that chooses among the results of evaluating the expressions
> it is provided, so
> (amb *someList*)
> evaluates *someList*, resulting in a list, and chooses that.  You could
> define a function
> (define (amb-list list)
>  (if (null? list)
>      (amb)
>      (amb (car list)
>           (amb-list (cdr list)))))
> It's also possible that the amb library provides such a function, which may
> be implemented more efficiently; I don't know which amb library you're using,
> so I can't help you there.
> [...]


if one of the two implementations of amb that can be found on PLaneT is
used, the function amb-list can probably be implemented more efficiently:

	* For (planet ("amb.scm" ("wmfarr" "amb.plt" 1 0))) try
    (define (amb-list choices)
      (let/cc choice-point
        (apply amb-thunks choice-point (map const choices))))
	* For (planet ("amb.ss" ("murphy" "amb.plt" 1 1))) try
    (define (amb-list choices)
      (apply amb-call (map const choices)))


When C++ is your hammer, every problem looks like your thumb.

Posted on the users mailing list.