next up previous
Next: Some rules Up: No Title Previous: Controlling Backtracking

Example 1

cinema_category(Age, children) :-
   Age =< 10.
cinema_category(Age, parental) :- 
   Age > 10, Age =< 16.
cinema_category(Age, adult) :-
   Age > 16.

Q: cinema_category(14,Category)
A: Category = parental
no more solutions

Same relation, using the cut :

cinema_category(Age, children) :-
   Age =< 10, !.
cinema_category(Age, parental) :- 
   Age > 10, Age =< 16, !.
cinema_category(Age, adult).

Q: cinema_category(14,Category)
A: Category = parental
no more solutions

This time, search tree has only 2 branches



Omer F Rana
Sun Feb 16 21:01:24 GMT 1997