Abstract
Let us summarise what we learned in Chapters 1 and 2 about what can happen to a goal:
-
1.
An attempt can be made to satisfy a goal. When we satisfy a goal, we search the database from the top. Two things can happen:
-
(a)
A matching fact (or rule head) can be found. In this case, we say the goal has been matched. We mark the place in the database, and instantiate any previously uninstantiated variables that have matched. If we matched against a rule, we shall first have to attempt to satisfy the subgoals introduced by the rule. If the goal succeeds, we then attempt to satisfy the next goal. In our diagrams, this is the goal in the next box below the arrow. If the original goal appears in a conjunction, this will be the goal to its right in the program.
-
(b)
No matching fact (or rule head) can be found. In this case, we say the goal has failed. We then attempt to re-satisfy the goal in the box above the arrowhead. If the original goal appears in a conjunction, then this will be the goal on its left in the program.
-
(a)
-
2.
We can attempt to re-satisfy a goal. First of all, we attempt to re-satisfy each of the subgoals in turn, the arrow retreating up the page. If no subgoal can be re-satisfied in a suitable way, we attempt to find an alternative clause for the goal itself. In this case, we must make uninstantiated any variables that became instantiated when the previous clause was chosen. This is what we mean by “undoing” all the work previously done by this goal. Next, we resume searching the database, but we begin the search from where the goal’s place-marker was previously put. As before, this new “backtracked” goal may either succeed or fail, and either step (a) or (b) above would occur.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 1994 Springer-Verlag Berlin Heidelberg
About this chapter
Cite this chapter
Clocksin, W.F., Mellish, C.S. (1994). Backtracking and the “Cut”. In: Programming in Prolog. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-97596-7_4
Download citation
DOI: https://doi.org/10.1007/978-3-642-97596-7_4
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-540-58350-9
Online ISBN: 978-3-642-97596-7
eBook Packages: Springer Book Archive