Questions tagged [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.

62 questions
0
votes
1 answer

Prolog Operator Expected Error

I have searched Prolog Operator expected error questions at stack overflow, however I can't identify the error I am getting : 4:26: Syntax error: Operator expected % 3.pl compiled 0.00 sec, 3 clauses The code is simple: inc(N,R) :- R is N + 1. %…
ed bale
  • 59
  • 1
  • 9
-2
votes
2 answers

Why do we use '!' in prolog

This is the code that i am trying to understand. co(X) :- co(X,[],L). co([],A,A):- write(A). co([X|Xs], A, L) :- p(X-Z,A,R), !, Z1 is Z+1, co(Xs, [X-Z1|R], L). co([X|Xs], A, L) :- co(Xs, [X-1|A], L). p(X-Y,[X-Y|R],R):- !. p(X,[H|Y], [H|Z]) :-…
Squirtle
  • 151
  • 1
  • 3
  • 11
1 2 3 4
5