mother(X, Y) :- parent(X, Y), female(X).
Xis the mother of
Xis a parent of
Approximate procedural reading: To show that
X is the
Y, first show that
X is a parent
Y, then show that
X is female.
Suppose we have the additional base clauses:
Now if we inquire:
parent(john, bill). parent(jane, bill). female(jane).
the clause of
| ?- mother(M, bill).
mother/2will be located, and the unifications
X=M, Y=billwill occur. (Parameter transmission is by unification.) Then
parent(M, bill)will be attempted, resulting in the unification
female(john)will be attempted, but will fail. Prolog will backtrack to
parent(M, bill)and look for another solution for this; it will succeed and unify
M=jane. Finally, it will attempt
female(jane), and succeed; so the inquiry will succeed, having performed the unification
Typically Prolog predicates work regardless of which arguments are
instantiated, and may instantiate the others. Thus
mother/2 works equally well for the calls
mother(jane,bill) [but the procedural reading is different in
each case.] Injudicious use of control predicates, particularly
``cut,'', can destroy this property.