generate and test

From: Vincent Penesich (vincent.penesich_at_student.kuleuven.ac.be)
Date: 03/07/05


Date: Mon, 7 Mar 2005 19:12:05 +0100

Hi all,

I'm getting kind of confused here. I seem to not understand the generate and
test paradigm, although I can see how it could be powerful. Suppose I have
this little thingy:

testje(X) :-
 genereer(Y),
 test(Y),
 X = Y.

genereer(Y) :-
 Y is random(5).
test(Y) :-
 Y > 2.

You probably see my purpose: generate a number, if it's larger than two,
it's ok. But I want Prolog to keep repeating this *until* it is ok. Instead
it just fails. I don't see why it won't try a "redo" in this case. Is there
a way of doing this? I thought that Prolog would try to accomplish the tail
to its best abilities, which means retrying until it is satisfied,
especially since there's a random number generator involved... Any help
would be greatly appreciated.