Next: , Up: amb api   [Index]


1.4.1.1 Core amb syntaxes

The following bindings are exported by the library (vicare language-extensions amb).

Syntax: with-ambiguous-choices ?body0 ?body ...

Initialise the dynamic environment for a new amb search and in such environment evaluates the ?body forms. Return the result of the last form.

Syntax: with-amb-exhaustion-handler ?handler ?thunk

Install in the dynamic environment a custom handler for search tree exhaustion. This syntax should be used in the body of with-ambiguous-choices, but before the first use of amb.

?handler must be an expression evaluating to a thunk: such thunk is called by amb whenever no more choices are available. ?thunk must be an expression evaluating to a thunk: it is evaluated while the custom handler is installed.

Syntax: amb ?expr ...

Evaluate one of the ?expr expressions and return its result; save in the dynamic environment a continuation that can be reinstated to reject the result of this ?expr and try with the next ?expr. The ?expr arguments are tried in the given order: left to right.

If the result of evaluating an ?expr is a promise (produced by delay): the promise is forced to produce the result.

When used with no arguments: reject the result of the most recent expr and reinstate the previous continuation to try the next expr.

When all the choices have been tried: raise a non–continuable exception with condition object components &who, &message, &amb-exhaustion.

It is an error if amb is used outside the dynamic environment prepared by with-ambiguous-choices.