Sometimes it is desirable to prevent Prolog from backtracking into alternative solutions. The basic tool available to the programmer to stop prolog from continuing futher in its backtrack is the cut operator. consider the following.
% (percent signs mean comments) % a is the parent of b, c, and d. parent(a,b). parent(a,c). parent(a,d).
Here the predicate
parent/2 succeeds more than once when
is called. To stop prolog from searching for more solutions after the first is found you would use the cut operator, like so.
?- parent(a,X), !.
This will have X equal to b (as it is the first possible solution) and look for no more solutions.