It’s easy to add a “context” parameter using package(edcg):
:- use_module(library(edcg)).
:- multifile edcg:pass_info/1.
edcg:pass_info(context).
edcg:pred_info(my_pred, 2, [context]).
my_pred(X, Y) -->>
Context/context, % Unify Context with the `context` passed argument
do_something(X, Y, Context.some_field).
This expands my_pred/2
into my_pred/3
:
my_pred(X, Y, Context) :-
do_something(X, Y, Context.some_field).