Satisfying Goals Summary
The following diagram shows the methods which were described in the previous section.
Figure: Evaluating a Sequence of Goals
Prolog evaluates the goal in turn. To do this, it works from left to right. All sequence of goals succeeds if they all succeed. If one goal fails, Prolog goes back to the previous goals one by one in the sequence and trying to satisfy them from right to left. All the sequence fails if they all fail. Whenever one goal succeeds, Prolog starts to work the goals again from left to right.
Figure: Evaluating/Re-evaluating a Goal
Summary of Evaluating / Re-evaluating a Goal
To find the goal, Prolog searches all the clauses from top to bottom. Prolog searches in the database until one is found. The goal succeeds if the Prolog matches a clause, and it is a fact. Evaluate the sequence of goals in the body of rule if it is a rule. Prolog continues to search the database for further matches if it is not a rule. The goal fails if the Prolog reaches the end of the database.