As I mentioned in the lecture, in our class we will use SWI-Prolog, which you should install on your own machine now.
A predicate in Prolog has a name and zero or more arguments. A predicate is defined by a series of clauses, which must appear together in a source file.
A clause is either a fact or a rule.
A fact contains a predicate name plus zero or more arguments:
color(blue). parent(eliska, karel).
A rule consists of a head and a body,
separated by the symbol :-
(pronounced "if"):
path(X, Y) :- edge(X, Z), path(Z, Y). different(P, Q, R) :- dif(P, Q), dif(Q, R), dif(P, R).
The head looks like a fact. The body contains one or more goals, which look like facts. Goals can be chained together using the operators
,
("and")
;
("or")
A query in Prolog looks like the body of a
rule: it contains one or more goals, possibly chained together with
',
' and/or ';
' .
parent(X, eliska). color(C), color(D), dif(C, D), similar(C, D).
The built-in
predicate '=
' is true when two terms are equal.
dif(X, Y)
is true when X
and Y are different.