meta_predicate/1 declaration

Synopsis

:- meta_predicate +MetaSpec

Provides for module name expansion of arguments in calls to the predicate given by MetaSpec. All meta_predicate/1 declarations must be at the beginning of a module.

Arguments


MetaSpec callable
Goal template or list of goal templates, of the form:
          functor(Arg1, Arg2,...)
          

Each Argn is one of:


:
requires module name expansion
integer >=0
same as :
+, -, ?, *
ignored

Description

All meta_predicate declarations must be at the beginning of a module, immediately after the module declaration, because the meta_predicate declarations need to be known at the time other modules are loaded if those modules use the meta-predicates.

The reason for allowing a non-negative integer as an alternative to : is that this may be used in the future to supply additional information to the cross-referencer (library(xref)) and to the Prolog compiler. An integer n is intended to mean that that that argument is a term, which will be supplied n additional arguments.

Represents DEC-10 Prolog-style "mode" declaration. Provides for module name expansion of arguments in MetaSpec.

Exceptions


context_error
Declaration appears in query.

Caveat

When a meta_predicate declaration is added, removed or changed, the file containing it, as well as all the modules that import the predicate given by MetaSpec, must be reloaded.

Examples

Consider a sort routine, mysort/3, to which the name of the comparison predicate is passed as an argument:

     mysort(+CompareProc, +InputList, -OutputList)
     

If CompareProc is module sensitive, an appropriate meta_predicate declaration for mysort/3 is:

     :- meta_predicate mysort(:, +, -).
     

This means that whenever a goal mysort(A, B, C) appears in a clause, it will be transformed at load time into mysort(M:A, B, C), where M is the source module. The transformation will happen unless

  1. A is of the form MetaSpec.
  2. A is a variable and the same variable appears in the head of the clause in a module-name-expansion position.

Many examples in library, e.g. library(samsort).

See Also

module/2 ref-mod-met