C Some others usefull predicates
The goal True/0 always succeeds.
is in fact equivalent to :
father=(jim,fred) :- true.
The goal repeat/0 is used to do a loop. The predicate in witch it is used is repated until every goal succeeds. Example :
test :- repeat,
write('Please enter a number'),
In this example the program will ask you to enter a number until you enter 42.
This predicate is used to launch another predicat. For example call(p) will run p.
Note that we can't write call(write('Hello World'),nl). because the predicate call/2 is not avaible in every Prolog.
setof/3 can be usefull if you want to find all the solutions of a predicate.
For example if we have this database :
If we want to find all the solutions of knows(X,Y). we can enter :
Z = [[jim,fred],[alf,bert]]
Bagof/3 is simmillar to setof/3. The difference is that bageof/3 leaves all repeated solutions while setof/3 removes them.