☰

*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:## Known bugs and planned improvements

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

PREDICATEfoldl/4

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

foldl(P, [X11,...,X1n], [Xm1,...,Xmn], V0, V) :- P(X11, ..., Xm1, V0, V1), ... P(Xn, ..., Xmn, Vn_1, Vn).

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:callable/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:callable/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:callable/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:callable/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:callable/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` is equivalent to:*Meta-predicate* with arguments: `foldr(pred(3),?,?,?)`.

foldr(P, [X11,...,X1n], [Xm1,...,Xmn], V0, V) :- P(Xn, ..., Xmn, V0, V1), ... P(X11, ..., Xm1, Vn_1, V).

Note that `foldr/N` 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,...,X1n], [Xm1,...,Xmn], V0, V) :- P(X11, ..., Xm1, Vn_1, V), ... P(Xn, ..., Xmn, V0, V1).

which is exactly like `foldl/N` but with fliped accumulator arguments. See `foldl/N` 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:callable/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:callable/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:callable/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:callable/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` is equivalent to:*Meta-predicate* with arguments: `maplist(pred(1),?)`.

maplist(P, [X11,...,X1n], [Xm1,...,Xmn]) :- P(X11, ..., Xm1), ... P(Xn, ..., Xmn).

Usage:`maplist(P,Xs)`

`P(X)` succeeds for each element X of Xs

*Call and exit should be compatible with:*

(`basic_props:callable/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:callable/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:callable/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:callable/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:callable/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`.

- We only provide foldr/4. Add more versions if needed.
- We do not provide scanl/N or scanr/N. Add them if needed.

Generated with LPdoc using Ciao