☰

*ON THIS PAGE*# Common higher-order predicates

**Author(s):** Daniel Cabeza, Manuel Carro, Edison Mera, Jose F. Morales.## Usage and interface

## Documentation on exports

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

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

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

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

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

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

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

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

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

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

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

## Documentation on imports

This module has the following direct dependencies:

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

PREDICATEfoldl/4

The left fold family `foldl/(n+3)` is equivalent to:*Meta-predicate* with arguments: `foldl(pred(3),?,?,?)`.

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.

*Call and exit should be compatible with:*

(`basic_props:cgoal/1`)P is a term which represents a goal, i.e., an atom or a structure.

(`basic_props:list/2`)Xs is a list of terms.

(`basic_props:term/1`)V0 is any term.

(`basic_props:term/1`)V is any term.*The following properties should hold at call time:*

(`term_typing:nonvar/1`)P is currently a term which is not a free variable.

PREDICATEfoldl/5

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

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

*Call and exit should be compatible with:*

(`basic_props:cgoal/1`)P is a term which represents a goal, i.e., an atom or a structure.

(`basic_props:list/2`)Xs is a list of terms.

(`basic_props:list/2`)Ys is a list of terms.

(`basic_props:term/1`)V0 is any term.

(`basic_props:term/1`)V is any term.*The following properties should hold at call time:*

(`term_typing:nonvar/1`)P is currently a term which is not a free variable.

PREDICATEfoldl/6

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

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

*Call and exit should be compatible with:*

(`basic_props:cgoal/1`)P is a term which represents a goal, i.e., an atom or a structure.

(`basic_props:list/2`)Xs is a list of terms.

(`basic_props:list/2`)Ys is a list of terms.

(`basic_props:list/2`)Zs is a list of terms.

(`basic_props:term/1`)V0 is any term.

(`basic_props:term/1`)V is any term.*The following properties should hold at call time:*

(`term_typing:nonvar/1`)P is currently a term which is not a free variable.

PREDICATEfoldl/7

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

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

*Call and exit should be compatible with:*

(`basic_props:cgoal/1`)P is a term which represents a goal, i.e., an atom or a structure.

(`basic_props:list/2`)Xs is a list of terms.

(`basic_props:list/2`)Ys is a list of terms.

(`basic_props:list/2`)Zs is a list of terms.

(`basic_props:list/2`)Us is a list of terms.

(`basic_props:term/1`)V0 is any term.

(`basic_props:term/1`)V is any term.*The following properties should hold at call time:*

(`term_typing:nonvar/1`)P is currently a term which is not a free variable.

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.

*Call and exit should be compatible with:*

(`basic_props:cgoal/1`)P is a term which represents a goal, i.e., an atom or a structure.

(`basic_props:list/2`)Xs is a list of terms.

(`basic_props:list/2`)Ys is a list of terms.

(`basic_props:list/2`)Zs is a list of terms.

(`basic_props:list/2`)Us is a list of terms.

(`basic_props:list/2`)Ws is a list of terms.

(`basic_props:term/1`)V0 is any term.

(`basic_props:term/1`)V is any term.*The following properties should hold at call time:*

(`term_typing:nonvar/1`)P is currently a term which is not a free variable.

PREDICATEfoldr/4

The right fold family `foldr/(n+3)` is equivalent to:*Meta-predicate* with arguments: `foldr(pred(3),?,?,?)`.

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.

*Call and exit should be compatible with:*

(`basic_props:cgoal/1`)F is a term which represents a goal, i.e., an atom or a structure.

(`basic_props:list/2`)Xs is a list of terms.

(`basic_props:term/1`)V0 is any term.

(`basic_props:term/1`)V is any term.*The following properties should hold at call time:*

(`term_typing:nonvar/1`)F is currently a term which is not a free variable.

(`term_typing:nonvar/1`)V0 is currently a term which is not a free variable.

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.

*The following properties should hold at call time:*

(`term_typing:nonvar/1`)SmallerThan is currently a term which is not a free variable.

(`basic_props:list/1`)List is a list.

(`basic_props:cgoal/1`)SmallerThan is a term which represents a goal, i.e., an atom or a structure.

(`basic_props:term/1`)Minimum is any term.

PREDICATEfilter/3

Usage:`filter(P,Xs,Ys)`

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

*Call and exit should be compatible with:*

(`basic_props:cgoal/1`)P is a term which represents a goal, i.e., an atom or a structure.

(`basic_props:list/1`)Xs is a list.

(`basic_props:list/1`)Ys is a list.*The following properties should hold at call time:*

(`term_typing:nonvar/1`)P is currently a term which is not a free variable.

(`term_typing:nonvar/1`)Xs is currently a term which is not a free variable.*The following properties should hold globally:*

(`native_props:is_det/1`)All calls of the form filter(P,Xs,Ys) are deterministic.

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)

*Call and exit should be compatible with:*

(`basic_props:cgoal/1`)P is a term which represents a goal, i.e., an atom or a structure.

(`basic_props:list/1`)Xs is a list.

(`basic_props:list/1`)Ys is a list.

(`basic_props:list/1`)Zs is a list.*The following properties should hold at call time:*

(`term_typing:nonvar/1`)P is currently a term which is not a free variable.

(`term_typing:nonvar/1`)Xs is currently a term which is not a free variable.

PREDICATEmaplist/2

The map list family `maplist/(n+1)` is equivalent to:*Meta-predicate* with arguments: `maplist(pred(1),?)`.

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

*Call and exit should be compatible with:*

(`basic_props:cgoal/1`)P is a term which represents a goal, i.e., an atom or a structure.

(`basic_props:list/1`)Xs is a list.*The following properties should hold at call time:*

(`term_typing:nonvar/1`)P is currently a term which is not a free variable.

(`term_typing:nonvar/1`)Xs is currently a term which is not a free variable.

PREDICATEmaplist/3

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

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

*Call and exit should be compatible with:*

(`basic_props:cgoal/1`)P is a term which represents a goal, i.e., an atom or a structure.

(`basic_props:list/1`)Xs is a list.

(`basic_props:list/1`)Ys is a list.*The following properties should hold at call time:*

(`term_typing:nonvar/1`)P is currently a term which is not a free variable.

(`term_typing:nonvar/1`)Xs is currently a term which is not a free variable.

PREDICATEmaplist/4

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

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

*Call and exit should be compatible with:*

(`basic_props:cgoal/1`)P is a term which represents a goal, i.e., an atom or a structure.

(`basic_props:list/1`)Xs is a list.

(`basic_props:list/1`)Ys is a list.

(`basic_props:list/1`)Zs is a list.*The following properties should hold at call time:*

(`term_typing:nonvar/1`)P is currently a term which is not a free variable.

(`term_typing:nonvar/1`)Xs is currently a term which is not a free variable.

PREDICATEmaplist/5

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

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

*Call and exit should be compatible with:*

(`basic_props:cgoal/1`)P is a term which represents a goal, i.e., an atom or a structure.

(`basic_props:list/1`)Xs is a list.

(`basic_props:list/1`)Ys is a list.

(`basic_props:list/1`)Zs is a list.

(`basic_props:list/1`)Vs is a list.*The following properties should hold at call time:*

(`term_typing:nonvar/1`)P is currently a term which is not a free variable.

(`term_typing:nonvar/1`)Xs is currently a term which is not a free variable.

PREDICATEmaplist/6

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

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

*Call and exit should be compatible with:*

(`basic_props:cgoal/1`)P is a term which represents a goal, i.e., an atom or a structure.

(`basic_props:list/1`)Xs is a list.

(`basic_props:list/1`)Ys is a list.

(`basic_props:list/1`)Zs is a list.

(`basic_props:list/1`)Vs is a list.

(`basic_props:list/1`)Ws is a list.*The following properties should hold at call time:*

(`term_typing:nonvar/1`)P is currently a term which is not a free variable.

(`term_typing:nonvar/1`)Xs is currently a term which is not a free variable.

*System library modules:*`native_props`.*Packages:*`prelude`,`initial`,`condcomp`,`assertions`,`assertions/assertions_basic`,`basicmodes`,`nativeprops`,`dcg`,`fsyntax`,`hiord`,`unittestdecls`.

Generated with LPdoc using Ciao