Reputation: 15316
This may be specific to SWI-Prolog.
How can I ask the system which module a predicate comes from?
For predicates, one can use predicate_property/2
:
?-
predicate_property(is_ordset(_),imported_from(M)).
M = ordsets.
Ok, so is_ordset/2
comes from module ordsets
.
I can also ask for the specific file that defines that module:
?-
predicate_property(is_ordset(_),file(F)).
F = '/usr/local/logic/swipl/lib/swipl/library/ordsets.pl'.
But how to do the same for operators, which may be defined in and exported from modules in the same way as predicates, at least in SWI-Prolog?
Upvotes: 1
Views: 154
Reputation: 18663
SWI-Prolog is one of the few Prolog systems where operators can be local to modules. A possible solution (but not ideal from a performance perspective) to find which module exported an operator is:
?- current_module(M),
module_property(M, exported_operators(Operators)),
member(Operator, Operators).
For example:
?- use_module(library(clpfd)).
true.
?- current_module(M),
module_property(M, exported_operators(Operators)),
member(op(Priority, Type, '#>'), Operators).
M = clpfd,
Operators = [op(760, yfx, #<==>), op(750, xfy, #==>), op(750, yfx, #<==), op(740, yfx, #\/), op(730, yfx, #\), op(720, yfx, #/\), op(710, fy, #\), op(700, xfx, #>), op(..., ..., ...)|...],
Priority = 700,
Type = xfx .
There might be a better solution...
Upvotes: 1