Example:


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

In the following program, the query p(X) 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 users 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 of the choice points that are created after Cp. In other words, the call lets Cp be the latest choice point. Note that Cp must be a reference to a choice point that is set by savecp(Cp).



Neng-Fa Zhou 2013-01-25