call/N family of predicates can call arbitrary Prolog goals at run time:
?- G=true, call(G). true. ?- G=(true,false), call(G). false.
maplist/3 are higher-order predicates, which allow the definition of a predicate to be lifted about a single element to lists of such elements. These predicates can be defined using
call/3 as building blocks and ship with many Prolog systems.
?- maplist(dif(a), [X,Y,Z]). dif(X, a), dif(Y, a), dif(Z, a).
In Prolog, the so-called meta-call is a built-in language feature. All Prolog code is represented by Prolog terms, allowing goals to be constructed dynamically and be used like other goals without additional predicates:
?- Goal = dif(X, Y), Goal. dif(X, Y).
Using this mechanism, other higher-order predicates can be defined in Prolog itself.
A fold (from the left) is a higher-order relation between:
For example: Use
foldl/4 to express the sum of all elements in a list, using a predicate as a building block to define the sum of two elements:
?- foldl(plus, [2,3,4], 0, S). S = 9.
To call a list of goals as if it were a conjunction of goals, combine the higher-order predicates call/1 and maplist/2:
?- Gs = [X = a, Y = b], maplist(call, Gs). Gs = [a=a, b=b], X = a, Y = b.