Slide 14.22: Rules Slide 14.24: Rules (cont.) Home |
?- mortal( P ).
The Prolog interpreter responds.
P = socrates yesThis means that Prolog was able to prove the goal by binding the variable
P
to socrates
.
This was done by again proving someone was mortal by proving the subgoal that they were human.
Prolog thus asked if there was any P
that was human.
This matches against the clause human(socrates)
thereby binding P
to socrates
.
This binding is then passed back to the parent goal, and the results in the printout we saw above.
fun(X) :- /* An item is fun if the item */ red(X), car(X). /* is red and it is a car. */ fun(X) :- /* Or an item is fun if the item */ blue(X), bike(X). /* is blue and it is a bike. */ fun(ice_cream). /* And ice cream is also fun. */This program says that we have three ways of finding out if something is fun. These three options are represent in Prolog by three clauses of the predicate
fun
.
If that does not succeed, we try the next clause.
We only fail when we run out of rules or facts to try.