|
Slide 14.27: Search Slide 14.29: Search (cont.) Home |
|
hold_party( X ) :- birthday( X ), happy( X ). birthday( tom ). birthday( fred ). birthday( helen ). happy( mary ). happy( jane ). happy( helen ).If we now pose the query
?- hold_party( Who ).
In order to solve the above query,
birthday, it being the first subgoal of birthday.
This binds X to tom.
happy(tom).
This will fail, since it doesn't match the above database.
birthday.
X to fred.
This then causes us to try the goal happy(fred).
Again this will fail to match our database.
birthday, and bind X to helen, and attempt the goal happy(helen).
This goal matches against clause 3 of our happy database.
hold_party will succeed with X=helen.