bagof(+Template, +Goal, -Bag)is used to collect a list
Bagof all the items
Templatethat satisfy some goal
Goal. Example: assume
likes(mary, pizza). likes(marco, pizza). likes(Human, pizza) :- italian(Human). italian(marco).Then
?- bagof(Person, likes(Person, pizza), Bag). Person = _G180 Bag = [mary, marco, marco]
Bag contains the item
twice, because there are two ways to prove that
likes pizza - the fact and via the rule.
bagof fails if
Goal has no solutions.
setof, and, for differences between