Information Technology Reference
In-Depth Information
Figure 3.9.
Queries using negated equality
?- parent(sam,X), \+ X=john.
X = jane
Yes
?- male(X), male(Y), male(Z).
X = john
Y = john
Z = john
Yes
?- male(X), male(Y), male(Z), \+ X=Y, \+ X=Z, \+ Y=Z.
X = john
Y = sam
Z = george
Yes
A review of programs and queries
Figure 3.10 reviews progress so far, with a few minor extensions. First, the word
term is introduced to mean a constant, variable, or number, and the word literal to
mean a possibly negated atom or equality. More significantly, the notion of a clause
is extended so that the body can be any query . So equalities and negations can now be
part of the body of a clause. These will be handled during back-chaining exactly as
they would be if they were part of a conjunctive query. For example, a clause like
has_two_children(X) :- child(Y1,X), child(Y2,X), \+ Y1=Y2.
can be in a program as a way of defining a new predicate has_two_children that
holds when a person X has (at least) two children. (Without the \+ Y1=Y2 literal, the
Y1 and Y2 could be the same child.)
3.3 Prolog back-chaining
This section examines in more detail the back-chaining procedure introduced in
chapter 2 to characterize exactly how Prolog goes about using a program that has
been loaded to establish a query. Figure 3.11 shows a new, simpler example program
called likes.pl .
 
 
Search WWH ::




Custom Search