creates a list with all solutions of a goal according to a given pattern.
findall/3 unifies TermList with a list with as many
instantiations of Term as Goal has solutions of Term.
If Goal does not succeed then TermList will be unified with
the emtpy list.
Term term Goal goal TermList list
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).
?- findall(Element, contains(What, Element), List).
Element = _1 What = _2 List = [window,door,room,table,floor,tile,table,floor,tile,tile]
?- setof(Element, contains(house, truck), List)
Element = _1 What = _2 List = []
This predicate is part of the ISO-Prolog Standard.
bagof/3 , setof/3 , collect/3.
| scroll to top |
|