1.4.4. Tracing
You will frequently want to see what Prolog does while it is evaluating
your programs. This is often necessary when you are trying to track down bugs in
your program. Unfortunately, Prolog's debugging environment is not very good. To
trace the execution of a goal (such as
grandmother(liz, Who).),
type
| ?-trace.
and then a goal, such as
| ?- grandmother(liz, Who).
Prolog will then output to the screen the sequence of steps it
carries out in executing this goal
| ?- grandmother(liz, Who).
1 1 Call: grandmother(liz,_260) ?
2 2 Call: mother(liz,_751) ?
3 3 Call: female(liz) ?
3 3 Exit: female(liz) ?
4 3 Call: parent(liz,_751) ?
4 3 Exit: parent(liz,chas) ?
2 2 Exit: mother(liz,chas) ?
5 2 Call: parent(chas,_260) ?
? 5 2 Exit: parent(chas,harry) ?
? 1 1 Exit: grandmother(liz,harry) ?
Who = harry ?
yes
{trace}
At each point where it calls a goal, Prolog pauses and
requires a carriage return from you before proceeding.
To turn off tracing,
type
| ?- nodebug. <return>
(Note the full stop!)