Описание тега meta-predicate

A meta predicate is a predicate that contains an argument defined over predicates or related to some module. In many Prolog systems, such predicates are declared with a directive (meta_predicate)/1.

A predicate is called a meta-predicate or higher-order predicate if one of its arguments denotes a predicate.

Meta-predicates are an important means for describing common patterns in a general and flexible way. For example, the common situation of describing a relation Rel_1 that holds for each element of a list can be defined abstractly as:

maplist(_, []).
maplist(Rel_1, [L|Ls]) :-
    call(Rel_1, L),
    maplist(Rel_1, Ls).

Rel_1 denotes a partial predicate indicator, which is called a closure. The higher-order predicate call/2 is used to call a closure with an additional argument.

Important and widely available meta-predicates are:

  • call/[2-8] call a closure with additional arguments
  • maplist/[2,3] denoting relations for each element of a list
  • foldl/4 describes a list traversal that keeps track of a state.

Richard O'Keefe's draft for An Elementary Prolog Library contains descriptions and implementations of many important meta-predicates.