This library implements a few basic higher-order predicates for reducing and transforming lists.
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.
Usage:foldl(P,Xs,Ys,V0,V)
Like foldl/4 but applied to successive tuples from Xs, Ys.
Usage:foldl(P,Xs,Ys,Zs,V0,V)
Like foldl/4 but applied to successive tuples from Xs, Ys, Zs.
Usage:foldl(P,Xs,Ys,Zs,Us,V0,V)
Like foldl/4 but applied to successive tuples from Xs, Ys, Zs, Us.
Usage:foldl(P,Xs,Ys,Zs,Us,Ws,V0,V)
Like foldl/4 but applied to successive tuples from Xs, Ys, Zs, Us, Ws.
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.
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.
Usage:filter(P,Xs,Ys)
Ys contains all elements X of Xs such that P(X) holds (preserving the order)
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)
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
Usage:maplist(P,Xs,Ys)
Like maplist/2 but applied to successive tuples from Xs, Ys.
Usage:maplist(P,Xs,Ys,Zs)
Like maplist/2 but applied to successive tuples from Xs, Ys, Zs.
Usage:maplist(P,Xs,Ys,Zs,Vs)
Like maplist/2 but applied to successive tuples from Xs, Ys, Zs, Vs.
Usage:maplist(P,Xs,Ys,Zs,Vs,Ws)
Like maplist/2 but applied to successive tuples from Xs, Ys, Zs, Vs, Ws.