“amb” provides John McCarthy’s ambiguous operator for Racket. It
introduces amb along with helpers such as for/amb and
in-amb for exploring nondeterministic computations. A typed version
is available in the typed-amb package.
raco pkg install amb
(require amb)raco pkg install ambraco pkg install typed-amb
(require typed/amb)raco pkg install typed-ambThe forms allow exploring multiple execution paths. The snippet below
collects all pairs (x y) such that x < y:
(require amb)
(for/list ([p (in-amb
(let ([x (amb 1 2 3)]
[y (amb 3 4 5)])
(when (>= x y) (amb))
(list x y)))])
p)This evaluates to
'((1 3) (1 4) (1 5) (2 3) (2 4) (2 5))Using typed/amb offers the same API for Typed Racket programs.
(require typed/amb)
;; Typed usage mirrors the untyped API