next up previous
Next: Removing duplicate items with Up: Obtaining More Solutions Previous: findall

bagof or setof

Consider the following database :

age(peter,7).
age(anne,5).
age(pat,8).
age(tom,5).

Q: bagof(Child, age(Child,5), List)
A: List = [anne,tom]

Q: bagof(Child, age(Child,Age), List)
A: Age = 7
   List = [peter];

   Age = 5
   List = [anne, tom];

   Age = 8
   List = [pat];

Q: bagof(Child, Age ^ age(Child,Age), List)
A: List = [peter,anne,pat,tom]

where ^ : is a predefined infix operator



Omer F Rana
Thu Feb 20 20:05:17 GMT 1997