apply.pl -- Apply predicates on a list
This module defines meta-predicates that apply a predicate on all members of a list.
- include(:Goal, +List1, ?List2) is det
- Filter elements for which Goal succeeds. True if List2 contains
those elements Xi of List1 for which
call(Goal, Xi)
succeeds. - exclude(:Goal, +List1, ?List2) is det
- Filter elements for which Goal fails. True if List2 contains
those elements Xi of List1 for which
call(Goal, Xi)
fails. - partition(:Pred, +List, ?Included, ?Excluded) is det
- Filter elements of List according to Pred. True if Included
contains all elements for which
call(Pred, X)
succeeds and Excluded contains the remaining elements. - partition(:Pred, +List, ?Less, ?Equal, ?Greater) is semidet
- Filter List according to Pred in three sets. For each element Xi
of List, its destination is determined by
call(Pred, Xi, Place)
, where Place must be unified to one of<
,=
or>
. Pred must be deterministic. - maplist(:Goal, ?List1)
- maplist(:Goal, ?List1, ?List2)
- maplist(:Goal, ?List1, ?List2, ?List3)
- maplist(:Goal, ?List1, ?List2, ?List3, ?List4)
- True if Goal is successfully applied on all matching elements of the
list. The maplist family of predicates is defined as:
maplist(P, [X11,...,X1n], ..., [Xm1,...,Xmn]) :- P(X11, ..., Xm1), ... P(X1n, ..., Xmn).
This family of predicates is deterministic iff Goal is deterministic and List1 is a proper list, i.e., a list that ends in
[]
. - convlist(:Goal, +ListIn, -ListOut) is det
- Similar to maplist/3, but elements for which
call(Goal, ElemIn, _)
fails are omitted from ListOut. For example (using library(yall)):?- convlist([X,Y]>>(integer(X), Y is X^2), [3, 5, 4.4, 2], L). L = [9, 25, 4].
- foldl(:Goal, +List, +V0, -V)
- foldl(:Goal, +List1, +List2, +V0, -V)
- foldl(:Goal, +List1, +List2, +List3, +V0, -V)
- foldl(:Goal, +List1, +List2, +List3, +List4, +V0, -V)
- Fold a list, using arguments of the list as left argument. The
foldl family of predicates is defined by:
foldl(P, [X11,...,X1n], ..., [Xm1,...,Xmn], V0, Vn) :- P(X11, ..., Xm1, V0, V1), ... P(X1n, ..., Xmn, V', Vn).
- scanl(:Goal, +List, +V0, -Values)
- scanl(:Goal, +List1, +List2, +V0, -Values)
- scanl(:Goal, +List1, +List2, +List3, +V0, -Values)
- scanl(:Goal, +List1, +List2, +List3, +List4, +V0, -Values)
- Left scan of list. The scanl family of higher order list
operations is defined by:
scanl(P, [X11,...,X1n], ..., [Xm1,...,Xmn], V0, [V0,V1,...,Vn]) :- P(X11, ..., Xm1, V0, V1), ... P(X1n, ..., Xmn, V', Vn).
Undocumented predicates
The following predicates are exported, but not or incorrectly documented.
- foldl(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)
- foldl(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)
- scanl(Arg1, Arg2, Arg3, Arg4, Arg5)
- scanl(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)
- scanl(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)
- maplist(Arg1, Arg2, Arg3, Arg4)
- maplist(Arg1, Arg2, Arg3)
- maplist(Arg1, Arg2, Arg3, Arg4, Arg5)
- foldl(Arg1, Arg2, Arg3, Arg4, Arg5)