Thanks @pmoura. My application (at least unless I go full prolog which might happen yet!) is calling out from python into prolog do some reasoning; so I’m more likely to be loading and unloading clauses into the db and making calls into it than loading from a file.
I may end up using modules as namespaces in which case Logtalk objects might be a better option, but am not there yet! Also, I’m guessing that running with trace on might slow things down giving me another reason to switch to the Logtalk solution if performance becomes an issue.
Thanks for the awesome support!
P.S. I wrapped up the trace recording and reading as record_trace
and pop_trace_recording
:
prolog_trace_interception(Port, Frame, _PC, continue) :-
prolog_frame_attribute(Frame, goal, Goal),
prolog_frame_attribute(Frame, level, Level),
recordz(trace, trace(Port, Level, Goal)).
:- meta_predicate record_trace(?).
record_trace(Goal):- trace, Goal, notrace.
pop_trace_recording(Value):-
recorded(trace, Value, Reference), erase(Reference).
With kb:
b(X):-d(X).
b(X):-a(X).
a(x).
d(y).
earth_spins.
Query with:
[debug] ?- record_trace(b(x)).
true.
[debug] ?- pop_trace_recording(V).
V = trace(call, 9, b(x)) ;
V = trace(call, 10, d(x)) ;
V = trace(fail, 10, d(x)) ;
V = trace(redo(0), 9, b(x)) ;
V = trace(call, 10, a(x)) ;
V = trace(exit, 10, a(x)) ;
V = trace(exit, 9, b(x)).