True if PredicateIndicator is a currently defined predicate.
A predicate is considered defined if it exists in the specified module,
is imported into the module or is defined in one of the modules from
which the predicate will be imported if it is called (see
section 5.9). Note that current_predicate/1
does not succeed for predicates that can be autoloaded.
See also
current_predicate/2
and predicate_property/2.
If PredicateIndicator is not fully specified, the
predicate only generates values that are defined in or already imported
into the target module. Generating all callable predicates therefore
requires enumerating modules using current_module/1.
Generating predicates callable in a given module requires enumerating
the import modules using import_module/2
and the autoloadable predicates using the
predicate_property/2 autoload.
Classical pre-ISO implementation of current_predicate/1,
where the predicate is represented by the head term. The advantage is
that this can be used for checking the existence of a predicate before
calling it without the need for functor/3:
call_if_exists(G) :-
current_predicate(_, G),
call(G).
Because of this intended usage, current_predicate/2
also succeeds if the predicate can be autoloaded. Unfortunately,
checking the autoloader makes this predicate relatively slow, in
particular because a failed lookup of the autoloader will cause the
autoloader to verify that its index is up-to-date.
True when Head refers to a predicate that has property
Property. With sufficiently instantiated Head,
predicate_property/2
tries to resolve the predicate the same way as calling it would do: if
the predicate is not defined it scans the default modules (see default_module/2)
and finally tries the autoloader. Unlike calling, failure to find the
target predicate causes
predicate_property/2
to fail silently. If Head is not sufficiently bound, only
currently locally defined and already imported predicates are
enumerated. See current_predicate/1
for enumerating all predicates. A common issue concerns generating
all built-in predicates. This can be achieved using the code below:
generate_built_in(Name/Arity) :-
predicate_property(system:Head, built_in),
functor(Head, Name, Arity),
\+ sub_atom(Name, 0, _, _, $). % discard reserved names
Property is one of:
- autoload(File)
-
True if the predicate can be autoloaded from the file File.
Like
undefined, this property is not generated.
- built_in
-
True if the predicate is locked as a built-in predicate. This implies it
cannot be redefined in its definition module and it can normally not be
seen in the tracer.
- dynamic
-
True if