In adding a hook for prolog_trace_interception/4 by using asserta/2 and then verifying the clause, when the clause uses predicates from different modules the asserted clause is not what I expected.
For example in a module named examples
is this asserta/2 in a predicate example_01/1
asserta(
(
user:prolog_trace_interception(Port, Frame, Choice, continue) :-
prolog_debug:debug('egt','@~a',['2a']),
user:format('Port: ~w, Frame: ~w, Choice: ~w~n',[Port,Frame,Choice])
),
Ref
)
right after calling asserta/2 is a call to check_01/1 (see below)
check_01(Module) :-
(
current_predicate(prolog_trace_interception/4), !,
nl,
listing(Module:prolog_trace_interception)
;
true
).
The call to check_01/1 lists the actual clause
:- dynamic prolog_trace_interception/4.
prolog_trace_interception(A, B, C, continue) :-
examples:
( prolog_debug:debug(egt, '@~a', ['2a']),
user:format('Port: ~w, Frame: ~w, Choice: ~w~n', [A, B, C])
).
The clause expected is
:- dynamic prolog_trace_interception/4.
prolog_trace_interception(A, B, C, continue) :-
prolog_debug:debug(egt, '@~a', ['2a']),
user:format('Port: ~w, Frame: ~w, Choice: ~w~n', [A, B, C]).
The actual clause works in running code.
I just want to make sure I did nothing wrong or that there is a more correct way to add the dynamic clause. If there is another way, the adding of the clause does not even have to be via assert, it could be via one of the lower level predicates that start with $
.
EDIT
After seeing reply by Jan W.
Using
asserta(
user:
(
prolog_trace_interception(Port, Frame, Choice, continue) :-
debug(egt, '@~a', ['2a']),
format('Port: ~w, Frame: ~w, Choice: ~w~n',[Port,Frame,Choice])
),
Ref
)
the call to check_01/1 now lists the actual clause as
:- dynamic prolog_trace_interception/4.
prolog_trace_interception(A, B, C, continue) :-
debug(egt, '@~a', ['2a']),
format('Port: ~w, Frame: ~w, Choice: ~w~n', [A, B, C]).