next up previous contents
Next: Commit Up: Modifying the Search Previous: Modifying the Search

A Special Control Predicate

We now present a solution to the practical problems posed in chapter 7 about how to control Prolog's search strategy. We summarised these issues as ones of:

In each of these cases the solution is to make use of a built-in predicate which always succeeds ---but with a very unpleasant side-effect. This notorious predicate is known as the cut and written !/0.

The reason why cut ( !/0) is so unpleasant are that it effects Prolog's search tree. Consequently, by adding a cut, the program's meaning may change radically. We sometimes say that a cut that does this is a red cut. On the other hand, the placing of a cut may not change the intended meaning but simply junk a part of the search tree where it is known that there is no legal solution. Such a cut is termed a green cut. The Art of Prolog by Sterling and Shapiro has a nice section on the cut [Sterling & Shapiro, 1986].

We now go over how to solve the three control problems.




Paul Brna
Mon May 24 20:14:48 BST 1999