amb ( seq -- elt )
Simple backtracking non-determinism

Prev:bag-of ( quot -- seq )
Next:amb-lazy ( seq -- elt )


Vocabulary
backtrack

Inputs
seqthe alternatives


Outputs
eltone of the alternatives


Word description
The amb (ambiguous) word saves the state of the current computation (through the continuations vocabulary) and returns the first alternative. When fail is invoked, the saved state will be restored and the next alternative will be returned. When there are no more alternatives, fail will go up one level to the location of the previous amb call. If there are no more calls up the chain, an error will be signalled.

See also
fail, cut-amb

Definition