Cut (logic programming)

The cut, in Prolog, is a goal, written as !, which always succeeds but cannot be backtracked. Cuts can prevent unwanted backtracking, which could add unwanted solutions and/or space/time overhead to a query.

The cut should be used sparingly. While cuts can be inserted into code containing errors, if a test is unnecessary because a cut has guaranteed that it is true, it is good practice to say so in a comment at the appropriate place.[1]

Some programmers call the cut a controversial control facility[2] because it was added for efficiency reasons only and is not a logical formula.

  1. ^ Dyckhoff, Roy (1994-05-20). Extensions of Logic Programming: 4th International Workshop, ELP '93, St Andrews, U.K., March 29 - April 1, 1993. Proceedings. Springer Science & Business Media. ISBN 978-3-540-58025-6.
  2. ^ Foundations of Logic Programming, Springer (2012).