When you enable trace mode with trace/0, the tracer will, by default, pause and wait for a command at every port it hits on every predicate. The leash/1 predicate can be used to modify the ports to pause at. This is a global setting, so changes will remain until they are changed again or SWI-Prolog is restarted. Disabling the tracer via notrace/0 doesn't affect which ports are leashed.
The leash/1 argument
must start with + to add, or - to remove,
followed by the name of a port such as call, exit,
etc. There are special terms like all which can be used
instead of manually adding or removing every port.
To stop only at the fail port, use leash/1 like this:
?- leash(-all). true. ?- leash(+fail). true. ?- trace. true. [trace] ?- noun(X, rock), adjective(X, color, red). Call: (11) noun(_3794, rock) Call: (12) is_a(_3794, rock) Exit: (12) is_a(rock1, rock) Exit: (11) noun(rock1, rock) Call: (11) adjective(rock1, color, red) Call: (12) color(rock1, red) Exit: (12) color(rock1, red) Exit: (11) adjective(rock1, color, red) X = rock1 ; Redo: (12) is_a(_3794, rock) Exit: (12) is_a(rock2, rock) Exit: (11) noun(rock2, rock) Call: (11) adjective(rock2, color, red) Call: (12) color(rock2, red) Fail: (12) color(rock2, red) ? creep Fail: (11) adjective(rock2, color, red) ? creep false.
Now, only the lines that start with "Fail:" have "creep" after them
because that was the only time the tracer paused for a command. To never
pause and just see all the traces, use leash(-all) and
don't turn any ports back on.
The default ports are still printed out because a different setting,
visible/1, controls
which ports are printed. visible/1
takes the same form of argument as leash/1.
To only stop and show the fail port, use
leash/1 and visible/1
like this:
?- leash(-all). true. ?- leash(+fail). true. ?- visible(-all). true. ?- visible(+fail). true. ?- trace. true. [trace] ?- noun(X, rock), adjective(X, color, red). X = rock1 ; Fail: (12) color(rock2, red) ? creep Fail: (11) adjective(rock2, color, red) ? creep false.