next up previous contents
Next: Finite and Infinite Up: Some General Program Previous: Some General Program

Generate --- Test

One of the most common techniques in Prolog is to use the backtracking in first generating a possible solution, then testing the possible solution to see if it is acceptable. If not, backtracking takes place so that another possible solution can be generated.

 generate_and_test( Info,X):-


generate( Info,X),

test( Info,X),


In the above schema, the ellipsis (...) indicates a number of subgoals (0 or more).

We can distinguish two kinds of generator: a finite generator and an infinite generator. We will illustrate with two different versions of a non-negative integer generator which we will call int/1 ---we cannot name this integer/1 since this is already defined (as a built-in predicate) and it only works with mode integer(+) and we want int/1 to work with mode int(-).

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