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