The effect of clause ordering


next up previous contents
Next: The cut
Up: Introduction to Prolog for Mathematicians
Previous: How Prolog works

The effect of clause ordering

Because Prolog searches for clauses from top to bottom, the order in which they are written makes a difference. If a predicate has several solutions, their order of appearence is determined by the order of the clauses.

If the conditions in alternative clauses are not mutually exclusive, then backtracking will produce them both:

has_fitness(Skier, poor) :-
    max_pressups(Skier, P),
    P < 15.

has_fitness(Skier, good) :-
    max_pressups(Skier, P),
    P >= 10.

max_pressups(eddie,12).



Jocelyn Paine
Mon Jul 17 22:27:41 BST 1995