Search code examples
prologtraceswi-prolog

Hide Predicates from Trace


Is there a way to hide individual predicates from the trace? In a rule like this:

p(<Stuff>) :-
    q(),
    p(<ModifiedStuff>);
    s(),
    p(<ModifiedStuff>);
    p(<ModifiedStuff>).

I would for example like to hide q() and s() from the trace, because I only am interested in the calls to p(). q() and s() might call a lot of other predicates, which totally cloggs up the trace and makes it hard to find the relevant calls in it.

edit 1

I have now tried executing from the command line rather than from inside the interpreter and piping the trace to grep for grepping lines containing p... but to my disappointment I had to realize when running from the command line, it still opens a prolog shell, so piping the output does not work at all. Only print will actually send to the shell running the prolog process.

edit 2 (output when using trace(p, all))

?- trace(shift_reduce, all).
%         shift_reduce/2: [call,redo,exit,fail]
true.

[debug]  ?- shift_reduce([λ,x,x], T).
 T Call: (8) shift_reduce([λ, x, x], _7344)
 T Exit: (8) shift_reduce([λ, x, x], [e, [λ], [v, [x]], [e, [v, [...]]]])
T = [e, [λ], [v, [x]], [e, [v, [x]]]] ;
 T Exit: (8) shift_reduce([λ, x, x], [e, [λ], [v, [x]], [e, [v, [...]]]])
T = [e, [λ], [v, [x]], [e, [v, [x]]]] ;
 T Fail: (8) shift_reduce([λ, x, x], _7344)
false.

[debug]  ?-

Solution

  • In SWI-Prolog you can use trace/2 like:

    trace(p, all) and this will enable information related to p and also this will activate debug mode.

    while you're on debug mode you can call:

    p(<Stuff>).
    

    and this will now show information only for p.