Tutorial by Examples

The 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/2 and 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/2 and call/3 as building blocks and ship with many Prolog systems. For example: ?- maplist(dif(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-or...
A fold (from the left) is a higher-order relation between: a predicate with 3 arguments a list of elements an initial state a final state, which is the result of applying the predicate to successive elements while carrying through intermediate states. For example: Use foldl/4 to express the...
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.

Page 1 of 1