meta_predicate(Template) meta_predicate((Template, ...)) meta_predicate([Template, ...]) meta_predicate(Entity::Template) meta_predicate((Entity::Template, ...)) meta_predicate([Entity::Template, ...]) meta_predicate(Module:Template) meta_predicate((Module:Template, ...)) meta_predicate([Module:Template, ...])
Declares meta-predicates, i.e., predicates that have arguments that will be called as goals. An argument may also be a closure instead of a goal if the meta-predicate uses the call/1-N Logtalk built-in methods to construct and call the actual goal from the closure and the additional arguments.
Meta-arguments which are goals are represented by the integer
Meta-arguments which are closures are represented by a positive integer,
N, representing the number of additional arguments that will be
appended to the closure in order to construct the corresponding meta-call.
Meta-arguments that will be called using the
predicates and that can thus be existentially-qualified are represented
by the atom
^. Normal arguments are represented by the atom
Meta-arguments are always called in the meta-predicate
calling context, not in the
meta-predicate definition context.
Logtalk allows the use of this directive to override the original meta-predicate directive. This is sometimes necessary when calling Prolog built-in meta-predicates or Prolog module meta-predicates due to the lack of standardization of the syntax of the meta-predicate templates.
Some backend Prolog compilers declare
meta_predicate as an operator
for a lighter syntax. But this makes the code non-portable and is
a practice best avoided.
Template and modes¶
meta_predicate(+meta_predicate_template_term) meta_predicate(+object_identifier::+meta_predicate_template_term) meta_predicate(+category_identifier::+meta_predicate_template_term) meta_predicate(+module_identifier:+meta_predicate_template_term)
% findall/3 second argument is interpreted as a goal: :- meta_predicate(findall(*, 0, *)). % both forall/2 arguments are interpreted as goals: :- meta_predicate(forall(0, 0)). % maplist/3 first argument is interpreted as a closure % that will be expanded to a goal by appending two % arguments: :- meta_predicate(maplist(2, *, *)).