current_predicate

This commit is contained in:
Vitor Santos Costa 2015-01-16 20:08:51 -08:00
parent 58357b1af4
commit 7a8f57eb63

View File

@ -1164,11 +1164,17 @@ predicate_erased_statistics(P,NCls,Sz,ISz) :-
/** @pred current_predicate( _A_, _P_)
Defines the relation: _P_ is a currently defined predicate whose name is the atom _A_.
Defines the relation: _P_ is a currently defined predicate whose name
is the atom _A_. This includes all predicates defined
within the module and all predicates explicitely imported by the
module, but not that system predicates that are visible by default.
YAP does not use autoloader by default, so autoloaded predicates are not
included.
*/
current_predicate(A,T) :-
'$system_module'(M),
'$ground_module'(T, M, T0),
strip_module(T, M, T0),
(
'$current_predicate'(A, M, T0, _)
;
@ -1202,20 +1208,31 @@ system_predicate(P) :-
@pred current_predicate( _F_) is iso
True if _F_ is the predicate indicator for a currently defined user or
library predicate.The indicator _F_ is of the form _Mod_:_Na_/_Ar_ or _Na/Ar_,
library predicate. The indicator _F_ is of the form _Mod_:_Na_/_Ar_ or _Na/Ar_,
where the atom _Mod_ is the module of the predicate,
_Na_ is the name of the predicate, and _Ar_ its arity.
Notice that this built-in differs from current_predicate/2 in that it also returns all system predicates, as they are available to every module.
*/
current_predicate(F0) :-
'$ground_module'(F0, M, F),
strip_module(F0, M, F),
F = A/Arity,
(
'$current_predicate'(N, M, S, _),
functor( S, N, Ar),
F = N/Ar
'$current_predicate'(A, M, T, _),
functor( T, A, Arity )
;
'$imported_predicate'(_Name, M, F, _S, _)
'$imported_predicate'(A, M, A/Arity, _T0, _)
;
M \= prolog,
'$current_predicate'(A, prolog, T, _),
functor( T, A, Arity )
;
M \= system,
'$current_predicate'(A, system, T, _),
functor( T, A, Arity )
).
'$imported_predicate'(A, ImportingMod, A/Arity, G, Flags) :-
'$get_undefined_pred'(G, ImportingMod, G0, ExportingMod),
functor(G, A, Arity),