% File cut.pl

% The following example illustrates the meaning of cut (!) in Prolog.
% Intuitively, a "!" means "no more solutions".
% The effect of evaluating a cut is to prune all the branches, 
% in the search tree, which are to the right of the branch with "!" 
% and depart from the node in which the "!" was introduced, and from
% its immediate ancestor.

p(X) :- q(X).
p(X) :- r(X), !.
p(X) :- s(X).

q(a).

r(b).
r(c).

s(d). 

% Example of session: 

/* 
alonzo 15% pl
Welcome to SWI-Prolog (Version 3.2.9)
Copyright (c) 1993-1999 University of Amsterdam.  All rights reserved.

For help, use ?- help(Topic). or ?- apropos(Word).

?- consult('cut.pl').
cut.pl compiled, 0.00 sec, 1,404 bytes.

Yes
?- p(X).

X = a ;

X = b ;

No
?- 
*/
