next up previous contents
Next: bagof/3 Up: Powerful Features ---Finding Previous: Stage 2

Stage 3

If you leave off the existential quantification the semantics of setof/3 becomes conditional on the status of Y at the time the predicate is called.

 
foo(2,3).

foo(3,4).

foo(4,3).

?- setof(X,foo(X,Y),Set).

Set = [2,4] [-5pt]

In this case, Set is the set of all X for which there is a specific (but somewhat arbitrary) Y such that foo(X,Y).

Note that the first argument is really a variable pattern which specifies which variables get put into the list of solutions and how they are to appear. For example:

 
?- setof(firstbit(X),Y^foo(X,Y),Set).

Set = [firstbit(2),firstbit(3),firstbit(4)] [-5pt]

Note also that any repeated solutions are removed and all the solutions are placed in a standard ordering.



Paul Brna
Mon May 24 20:14:48 BST 1999