Common higher-order predicates

Author(s): Daniel Cabeza, Manuel Carro, Edison Mera, Jose F. Morales.

This library implements a few basic higher-order predicates for reducing and transforming lists.

Usage and interface

Documentation on exports

PREDICATEfoldl/4
The left fold family foldl/(n+3) is equivalent to:

foldl(P, [X11, ..., X1m], ..., [Xn1, ..., Xnm], V0, V) :-
    P(X11, ..., Xn1, V0, V1),
    ...
    P(X1m, ..., Xnm, Vm_1, V).

where P is a predicate of arity n+2, i.e., of type pred(n+2).

Usage:foldl(P,Xs,V0,V)

Reduces (fold) Xs from the left applying P and using V0-V as accumulator.

Meta-predicate with arguments: foldl(pred(3),?,?,?).

PREDICATEfoldl/5

Usage:foldl(P,Xs,Ys,V0,V)

Like foldl/4 but applied to successive tuples from Xs, Ys.

Meta-predicate with arguments: foldl(pred(4),?,?,?,?).

PREDICATEfoldl/6

Usage:foldl(P,Xs,Ys,Zs,V0,V)

Like foldl/4 but applied to successive tuples from Xs, Ys, Zs.

Meta-predicate with arguments: foldl(pred(5),?,?,?,?,?).

PREDICATEfoldl/7

Usage:foldl(P,Xs,Ys,Zs,Us,V0,V)

Like foldl/4 but applied to successive tuples from Xs, Ys, Zs, Us.

Meta-predicate with arguments: foldl(pred(6),?,?,?,?,?,?).

PREDICATEfoldl/8

Usage:foldl(P,Xs,Ys,Zs,Us,Ws,V0,V)

Like foldl/4 but applied to successive tuples from Xs, Ys, Zs, Us, Ws.

Meta-predicate with arguments: foldl(pred(7),?,?,?,?,?,?,?).

PREDICATEfoldr/4
The right fold family foldr/(n+3) is equivalent to:

foldr(P, [X11, ..., X1m], ..., [Xn1, ..., Xnm], V0, V) :-
    P(X1m, ..., Xnm, V0, V1),
    ...
    P(X11, ..., Xn1, Vm_1, V).

where P is a predicate of arity n+2, i.e., of type pred(n+2).

Note that foldr/(n+3) is not tail recursive. When P(...,?,?) is a valid calling mode, it would be possible to reorder the calls as in:

foldr_tail(P, [X11, ..., X1m], ..., [Xn1, ..., Xnm], V0, V) :-
    P(X11, ..., Xn1, Vm_1, V),
    ...
    P(X1m, ..., Xnm, V0, V1).

which is exactly like foldl/(n+3) but with flipped accumulator arguments. See foldl/(n+3) examples.

Usage:foldr(F,Xs,V0,V)

Reduces (fold) Xs from the right applying P and using V0-V as accumulator.

Meta-predicate with arguments: foldr(pred(3),?,?,?).

PREDICATEminimum/3

Usage:minimum(List,SmallerThan,Minimum)

Minimum is the smaller in the nonempty list List according to the relation SmallerThan: SmallerThan(X, Y) succeeds iff X is smaller than Y.

Meta-predicate with arguments: minimum(?,pred(2),?).

PREDICATEfilter/3

Usage:filter(P,Xs,Ys)

Ys contains all elements X of Xs such that P(X) holds (preserving the order)

Meta-predicate with arguments: filter(pred(1),?,?).

PREDICATEpartition/4

Usage:partition(P,Xs,Ys,Zs)

Ys contains all elements X of Xs such that P(X) holds, and Zs all that does not (preserving the order)

Meta-predicate with arguments: partition(pred(1),?,?,?).

PREDICATEmaplist/2
The map list family maplist/(n+1) is equivalent to:

maplist(P, [X11, ..., X1m], ..., [Xn1, ..., Xnm]) :-
    P(X11, ..., Xn1),
    ...
    P(X1m, ..., Xnm).

where P is a predicate of arity n, i.e., of type pred(n).

Usage:maplist(P,Xs)

P(X) succeeds for each element X of Xs

Meta-predicate with arguments: maplist(pred(1),?).

PREDICATEmaplist/3

Usage:maplist(P,Xs,Ys)

Like maplist/2 but applied to successive tuples from Xs, Ys.

Meta-predicate with arguments: maplist(pred(2),?,?).

PREDICATEmaplist/4

Usage:maplist(P,Xs,Ys,Zs)

Like maplist/2 but applied to successive tuples from Xs, Ys, Zs.

Meta-predicate with arguments: maplist(pred(3),?,?,?).

PREDICATEmaplist/5

Usage:maplist(P,Xs,Ys,Zs,Vs)

Like maplist/2 but applied to successive tuples from Xs, Ys, Zs, Vs.

Meta-predicate with arguments: maplist(pred(4),?,?,?,?).

PREDICATEmaplist/6

Usage:maplist(P,Xs,Ys,Zs,Vs,Ws)

Like maplist/2 but applied to successive tuples from Xs, Ys, Zs, Vs, Ws.

Meta-predicate with arguments: maplist(pred(5),?,?,?,?,?).

Documentation on imports

This module has the following direct dependencies: