Trace prolog predicat and force to anonymize/hide specific parameters?

I have some prolog code like this:

nextA("Terra", "Michelle").
nextA("Terra", "Max").
nextA("Marie", "Claudia").
nextA("Ed", "Larissa").


nextB("Terra", "Tom").
nextB("Tom", "Bob").
nextB("Tom", "Karl").
nextB("Michelle", "Tom").
nextB("Michelle", "Ed").
nextB("Michelle", "Stephane").

cond1(Step, Solution) :-
	once(nextA(Step, NextStep)),
	relations(NextStep, Solution0),
	union([Step], Solution0, Solution).

relations(Step, Solution) :-
	cond1(Step, Solution).

relations(Step, Solution) :-
	not(cond1(Step, Solution)),
	nextB(Step, NextStep),
	relations(NextStep, Solution0),
	union([Step], Solution0, Solution).

relations(Step, [Step]) :- not(nextA(Step, S)), not(nextB(Step, S)).

If I now want to trace this one in swiprolog debugger with commands

trace(relations).
relations(X,Y).

the output is:

 T [10] Call: relations(_28494, _28496)
 T [20] Call: relations("Michelle", _29736)
 T [29] Call: relations("Tom", _30636)
 T [38] Call: relations("Bob", _31536)
 T [38] Exit: relations("Bob", ["Bob"])
 T [29] Exit: relations("Tom", ["Tom", "Bob"])
 T [20] Exit: relations("Michelle", ["Michelle", "Tom", "Bob"])
 T [10] Exit: relations("Terra", ["Terra", "Michelle", "Tom", "Bob"])

is there a way (without rewriting the relations predicate) to trace only the first parameter in a way the output is something like that?

 T [10] Call: relations(_28494)
 T [20] Call: relations("Michelle", ??)
 T [29] Call: relations("Tom", ??)
 T [38] Call: relations("Bob", ??)
 T [38] Exit: relations("Bob", ??)
 T [29] Exit: relations("Tom", ??)
 T [20] Exit: relations("Michelle", ??)
 T [10] Exit: relations("Terra", ??)

is their furthermore some way to force the debugger to write the results in some .txt-file?

There is protocol/1 for logging the output.

To remove the unreadable ANSI formatting, you can use

?- set_prolog_flag(color_term, false)

To alter the debugger output, you can try prolog_trace_interception/4. I’m not sure how it interacts with protocolled output…

It’s possible that you will notice some misalignment wrt the unify debugger port (btw, in my experience, unification failure is often the primary cause of program misbehaviour). Now I think that with the advanced indexing that has been added recently changes the plain old Prolog execution model (linear scan of predicates matching by head unification), and then the usefulness of the unify port was lost.

Note that your program is non terminating, you can use - more or less - the following pattern:

go :-
    set_prolog_flag(color_term, false),
    protocol('p.txt'),
    leash(-all),
    trace,
    relations(_X,_Y),
    !,
    nodebug,
    noprotocol.
go :-
    nodebug,
    noprotocol.
2 Likes