Spy on condition?

Is there a way to set a spy point on a predicate for a specific condition?

E.g., I’d like to do spy(foo(some_complex_struct(...))) … but if I do that, spy just sets a spypoint for foo/1, which is more general than I want.

My current way of doing this is to add a clause to foo and re-consult:

foo(some_complex_struct(...)) :-
    trace, fail.
foo(...) :- ... % the rest of the foo clauses

I’m not aware of that functionality in SWI-Prolog. I do have it in the Logtalk debugger:

https://logtalk.org/manuals/userman/debugging.html#defining-context-spy-points

With some details on your code, I may be able to tell if you could run it through the Logtalk debugger.

I do pretty much what you do - add a clause to the top.
I often leave them in the code, as

foo(X) :-
   debugging(my_module(foo)),
    the_case_im_interested_in(X),
    gtrace, 
    fail.
foo(...) :- ... % the rest of the foo clauses

If you also call debug/3 before debugging/1 (on a diff topic) you now have a selective logging system, and can leave it in the code.

Such a thing doesn’t exist. There are break points though that allow you to break at a specific subgoal in a specific clause. That is a little hard to specify from the command line and thus requires editor support. It is in PceEmacs as well as in the graphical tracer and SWISH.

Real conditions are technically not that hard as the tracer can be hooked in Prolog and thus all it needs is a hook that evaluates the condition and continues silently or starts tracing. I never felt enough need for it. Just editing the source is typically a pretty good interface and as you can reload it without stopping the program it doesn’t affect the workflow much.

Typically a do a git commit after writing the code (PceEmacs already ensures there are no syntax errors and also catches most typos, forgotten predicates, etc). Then one can edit during debugging, both adding conditional trace calls, debug/3 statements and fixing stuff. When done, commit (–amend) the chunks that you want to keep and do a git reset --hard to dispose of the stuff you do not want to keep.