Trace: watching how Prolog works

Load the knowledge base kb2.pl.
?- consult('kb2.pl').
% kb2.pl compiled 0.00 sec, 1,304 bytes
yes

Then type trace. and hit return:

?- trace.
yes

Now, Prolog is in trace mode and will show you step by step how it is searching for answers. For example, pose the query happy(aunt_petunia). Prolog will show you the first goal that is sets out to prove:
Call: (7) happy(aunt_petunia)

Hitting return will show you the next step. In lines starting with Call Prolog is telling which is the goal that it is at the moment attempting to prove. Fail: ... means that the specified goal failed, and Exit: ... means that it succeeded. With Redo: ... Prolog is telling that it is trying to find an alternative way of proving a goal which it has already attempted to prove before.

Finish stepping through this trace and do traces for the other queries that we discussed in the lecture. I.e. pose the query happy(X) with respect to knowledge base kb2.pl and the query wizard(X) with respect to the knowledge base kb3.pl.

notrace turns the trace mode off. In SWI Prolog, the trace mode is only active for one query after typing trace.

Back to the exercises


Last modified: Thu Oct 13 10:42:37 CEST 2005