sitelogo
!(Cut)/0

causes the goal to succeed only once.

!/0

!/0 (Cut) succeeds exactly once. Unexplored branches of the search-tree get cutted. If Cut is part of a goal then all choicepoints of that goal are removed. That means that all bindings are fixed.
If Cut is set on the right place (mostly at the beginning of the body) then the complete goal can succeed only once.
The use of Cut is also important when building loops with repeat/0 because !/0 prevents that after leaving a loop this loop will be revisited by backtracing.
Using !/0 makes programs difficult to read. Therefore Cuts should be used as rarely as possible.

Examples

Assume that the database contains: 
     colour(blue).
     colour(red).
     colour(yellow).
     clothing(blouse).
     clothing(trousers).
     clothing(socks).

colour(X),!. Succeeds once with substitution X <- blue.
clothing(X),!,colour(Y). Succeeds three times with substitution
X <- blouse, Y <- blue.
X <- blouse, Y <- red.
X <- blouse, Y <- yellow.

Standard

This predicate is part of the ISO-Prolog Standard.

See also

abort/0, break/0, call/1, fcall/1, catch/3, ','(conjunction)/2, ';'(disjunction)/2, fail/0, true/0, halt/0/1, '->'(if-then)/2, ';'(if-then-else)/2, '\+'(not provable)/1, once/1, repeat/0, throw/1.


Darueber read on...
scroll to top managed with ubiCMS