Example:


\begin{picture}(380,1)(0,0)
\put (0,0){\framebox{(}380,1)}
\end{picture}

The query p(X) for the following program only gives one solution p(1). The cut removes the choice points for p(X) and q(X), and thus no further solution will be returned when you force backtracking by typing ';'. Without the cut, the query p(X) would have three solutions.

     p(X):-q(X),!.
     p(3).

     q(1).
     q(2).

\begin{picture}(380,1)(0,0)
\put (0,0){\framebox{(}380,1)}
\end{picture}

When a failure occurs, the execution will backtrack to the latest choice point, i.e., the latest subgoal that has alternative clauses. There are two non-standard built-ins, called savecp/1 and cutto/1, which can make the system backtrack to a choice point deep in the search tree. The call savecp(Cp) binds Cp to the latest choice point frame, where Cp must be a variable. The call cutto(Cp) discards all the choice points created after Cp. In other words, the call lets Cp be the latest choice point. Notice that Cp must be a reference to a choice point set by savecp(Cp).



Neng-Fa Zhou 2012-01-03