- Up - | Next >> |
The predicate
findall/3
.
findall/3
is a predicate for finding all solutions to a goal or a sequence of goals. Queries of the form
findall(+Object, +Goal, -List)
compute a list of all instantiations of Object
that satisfy Goal
. The query
?- findall(X, happy(X), L).
for example, would give you a list of all instantiations of X
such that happy(X)
is satisfied. Object
doesn't necessarily have to be a variable. For example,
?- findall(happy_duck(X), (happy(X), duck(X)), L).
would give you a list with all instantiations of happy_duck(X)
such that happy(X), duck(X)
is satisfied. So, assuming that your database looks as follows
duck(tick).
duck(trick).
duck(track).
duck(dagobert).
happy(tick).
happy(trick).
happy(track).
Prolog would answer
L = [happy_duck(tick), happy_duck(trick), happy_duck(track)]
- Up - | Next >> |