! [ISO]

The cut operator is used for pruning alternative solutions, unexplored alternative branches are not considered any more after a cut has been encountered. A cut is often used to indicate to the Prolog interpreter that clauses with the same functor and arity are exclusive, i.e. if one has matched then no alternative clause should be considered.

see also: ;/2 ,/2 operators

Suppose the current compiled module contains the following predicates:

test1(X, Y) :-
    atomic(X), !, Y=atomic.
test1(X, Y) :-
    compound(X), !, Y=compound.
test1(X, Y) :-
    !, Y=something_else.

test2(X, Y) :-
    atomic(X), Y=atomic.
test2(X, Y) :-
    compound(X), Y=compound.
test2(X, Y) :-
    !, Y=something_else.

The clauses of test2/2 are the same as test1/2 except that the test2/2 clauses do not contain the ! operator.

Examples
test1(a, Y). The only goal found unifies Y with atomic.
  Y=atomic
test2(a, Y). Two solutions are found:
  Y=atomic
  Y=something_else

 

 

info@trinc-prolog.com