| creates a sorted list with all solutions of a goal for all instantiations of the free variables in that goal with duplicates removed.
setof(+Term, +(Template ^ Goal), ?TermList)
setof(+Term, +Goal, ?TermList)
setof/3 unifies TermList for each different instantiation of
the free variables in Goal with a sorted list of all instantiations
of Term where Goal is a solution of Term. Duplicates will
not be part of the list.
Each variable, wich occurs in Goal and does not occur in
Term or Template is called a free variable.
Arguments
Term term
Template term
Goal goal
TermList list
Examples
part_of(house, window).
part_of(house, door).
part_of(house, room).
part_of(room, table).
part_of(room, floor).
part_of(floor, tile).
contains(X, Y) :- part_of(X, Y).
contains(X, Y) :- part_of(X, Z), contains(Z, Y).
?- setof(Element, contains(What, Element), List).
Element = _1
What = house
List = [door,floor,room,table,tile,window] ;
Element = _1
What = room
List = [floor,table,tile] ;
Element = _1
What = floor
List = [tile]
?- setof(Element, What ^ contains(What, Element), List).
Element = _1
What = _2
List = [door,floor,room,table,tile,window]
?- setof(Element, contains(house, truck), List)
no
Standard
This predicate is part of the ISO-Prolog Standard.
See also
bagof/3,
findall/3.
|