On this page:
amb:   Ambiguous Operator
9.3

amb: Ambiguous Operator🔗ℹ

 (require amb) package: amb

The amb library provides John McCarthy’s ambiguous operator for nondeterministic programming in direct style. A choice is an ordinary expression: (amb 1 2 3) returns one of its alternatives, and the rest of the computation runs once for each of them as the search demands it. A search reports the results of those runs.

Example:
> (for/list ([x (in-amb (let ([a (amb 1 2 3)]
                              [b (amb 10 20)])
                          (when (odd? (+ a b)) (amb))
                          (list a b)))])
    x)

'((2 10) (2 20))

Choices, and the other effects, can only be used within the dynamic extent of a search. The library is organized in three layers:

This is version 3 of the library. It is not compatible with version 2; Changes from Version 2 lists the differences.

    1 Evaluation Model

    2 Choices, Observers, and Local Searches

      2.1 Choices

      2.2 Observing a Search

      2.3 Local Searches and First Answers

        2.3.1 The First Answer of a Search

    3 The Core: Generators and Effects

      3.1 The Generator Protocol

      3.2 Core Primitives

      3.3 Code That Supplies Alternatives

    4 Mergers

      4.1 What a Merger Must Do

      4.2 Laws That a Merger May Satisfy

      4.3 Fairness Needs Pauses

    5 Search Boundaries and Exceptions

      5.1 Where Host Code Runs

      5.2 After an Exception

    6 Typed Interface

      6.1 Types

      6.2 The Trusted Boundary

      6.3 Known Typed Racket Limitations

    7 Changes from Version 2