2.10 Prolog implementations usually provide debugging facilities that enable the interactive tracing of the execution of goals.

Question:

2.10 Prolog implementations usually provide debugging facilities that enable the interactive tracing of the execution of goals. Such tracing gives similar insights as our diagrammatic traces in Figures 1.9 and 2.13-15. A typical use of the Prolog trace facility is as follows. Assume that you have already started your Prolog system and consulted the files with the parent relation and the versions of the ancestor relation in Figure 2.12. The interaction with Prolog to trace the execution of the goal anc1( tom,pat) will look something like this (with explanatory comments added): ?-trace. yes ?- anc1(tom, pat). 11 Call: anc1( tom,pat)? 2 2 Call: parent(tom,pat)? 2 2 Fail: parent(tom,pat)? 3 2 Call: parent(tom,_1035)? 3 2 Exit: parent(tom,bob)? 4 2 Call: anc1(bob,pat)? % This command puts Prolog into the trace mode % Prolog says it started to execute anc1(...) % Now Prolog stops, user may press "enter" key % Prolog started to execute subgoal parent(...) % User presses "enter" again % Prolog says that this subgoal has failed % Prolog now tries 2nd clause of ancl % parent( tom,bob) succeeded 5 3 Call: parent(bob,pat)? 5 3 Exit: parent( bob,pat)? 4 2 Exit: anc1(bob,pat)? 11 Exit: ancl(tom,pat)? yes % anc1(tom, pat) succeeded The left column shows the consecutive numbers of the goals tried, and the num- bers in the next column are the levels of 'calling' the goals (i.e. number of clause applications before a goal is reached). Compare this Prolog trace with the dia- gram of Figure 1.9 and find the correspondences. Trace with Prolog the goals anc2( tom,pat), anc3( tom,pat) and anc4( tom,pat). Compare these Prolog traces with Figures 2.13-15.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: