projog

3.64. ! - the "cut".

The "cut", represented as a !, is a special mechanism which affects how prolog backtracks.

Examples

?- repeat, !.

yes;

no

print_first_sentence(X) :-
atom_chars(X, Chars), member(Next, Chars), write(Next), Next=='.', !.

?- print_first_sentence('word1 word2 word3. word4 word5 word6.').
word1 word2 word3.
yes

a(x, Y) :- Y = 1, !.
a(X, Y) :- Y = 2.

?- a(x, Y).
Y = 1

yes

?- a(y, Y).
Y = 2

yes

?- a(z, Y).
Y = 2

yes