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

**URL:** <https://swi-prolog.discourse.group/t/trace-prolog-predicat-and-force-to-anonymize-hide-specific-parameters/5595>\
**Category:** General\
**Created:** [July 10, 2022, 5:19am UTC](https://swi-prolog.discourse.group/t/trace-prolog-predicat-and-force-to-anonymize-hide-specific-parameters/5595 "2022-07-10T05:19:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Losbarthos](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/losbarthos/32/4037_2.png) [@Losbarthos](https://swi-prolog.discourse.group/u/Losbarthos)\
**Post date:** [July 10, 2022, 5:19am UTC](https://swi-prolog.discourse.group/t/trace-prolog-predicat-and-force-to-anonymize-hide-specific-parameters/5595/1 "2022-07-10T05:19:57Z")

</div>

I have some prolog code like this:

```prolog
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

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

```

the output is:

```prolog
 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?

```prolog
 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?

---

<div class="post-metadata">

**Author:** ![CapelliC](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/capellic/32/17_2.png) [@CapelliC](https://swi-prolog.discourse.group/u/CapelliC)\
**Post date:** [July 10, 2022, 5:43am UTC](https://swi-prolog.discourse.group/t/trace-prolog-predicat-and-force-to-anonymize-hide-specific-parameters/5595/2 "2022-07-10T05:43:26Z")

</div>

There is [protocol/1](https://www.swi-prolog.org/pldoc/man?section=protocol) 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](https://www.swi-prolog.org/pldoc/man?section=tracehook). 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:

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

```
