next up previous contents index
Next: Invoking Predicates on all Up: Built-in predicates Previous: Sorting Lists   Contents   Index

Finding all Solutions to a Goal

findall3+Var, +Goal, -Bag Creates a list of the instantiations Var gets successively on backtracking over Goal and unifies the result with Bag. Succeeds with an empty list if Goal has no solutions. findall3 is equivalent to bagof3 with all free variables bound with the existence operator (), except that bagof3 fails when goal has no solutions. bagof3+Var, +Goal, -Bag Unify Bag with the alternatives of Var, if Goal has free variables besides the one sharing with Var bagof will backtrack over the alternatives of these free variables, unifying Bag with the corresponding alternatives of Var. The construct +VarGoal tells bagof not to bind Var in Goal. bagof3 fails if Goal has no solutions.

The example below illustrates bagof3 and the operator. The variable bindings are printed together on one line to save paper.
\begin{code}
2 ?- listing(foo).
\par foo(a, b, c).
foo(a, b, d).
foo(b, c, e).
f...
...s = [c, d] ;
A = G324, B = c, C = G326, Cs = [e, f, g] ;
\par No
5 ?-
\end{code}

setof3+Var, +Goal, -Set Equivalent to bagof3, but sorts the result using sort2 to get a sorted list of alternatives without duplicates.


next up previous contents index
Next: Invoking Predicates on all Up: Built-in predicates Previous: Sorting Lists   Contents   Index
Dr. Richard Botting 2001-12-12