next up previous contents
Next: Powerful Features ---Find Up: Powerful Features ---Finding Previous: Stage 3

bagof/3

The only difference between bagof/3 and setof/3 is that bagof/3 leaves repeated solutions in the answer. Note that bagof/3 is less expensive than setof/3.

Also note that, if there are no solutions then both bagof/3 and setof/3 fail! If you want a predicate that behaves like setof/3 (or bagof/3) but succeeds with an empty list if there are no solutions then write something like:

 
all(X,Y,Z):-

setof(X,Y,Z),

!.

all(X,Y,[]). [-5pt]

which will behave in the desired way.



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