![]() |
YAP 7.1.0
|
The routines are available once included with the use_module(library(maplist))
command Examples:
success
?- maplist(plus(1), [1,2,3,4], [2,3,4,5])
?- checklist(var, [X,Y,Z])
?- selectlist(<(0), [-1,0,1], [1])
?- convlist(plus_if_pos(1), [-1,0,1], [2])
?- sumlist(plus, [1,2,3,4], 1, 11)
?- maplist(mapargs(number_atom),[c(1),s(1,2,3)],[c('1'),s('1','2','3')]) ~~~~
Modules | |
Apply Interface to maplist | |
This library provides a SWI-compatible set of utilities for applying a predicate to all elements of a list. | |
class maplist/3 |
maplist( 2:Pred, + List1,+ List2)
maplist(: Pred, ? L1, ? L2 )
Apply Pred on all successive pairs of elements from List1 and List2 Fails if Pred can not be applied to a pair See the example above
L1 and L2 are such that call( _Pred_, _A1_, _A2_)
holds for every corresponding element in lists L1, L2
Comment from Richard O'Keefe: succeeds when Pred( _Old, New) succeeds for each corresponding Gi in Listi, New in NewList In InterLisp, this is MAPCAR It is also MAP2C Isn't bidirectionality wonderful?
class maplist/4 |
maplist(3:Pred,+ List1,+ List2,+ List4)
maplist(: Pred, ? L1, ? L2, ? L3)
Apply Pred on all successive triples of elements from List1, List2 and List3 Fails if Pred can not be applied to a triple See the example above
L1, L2, and L3 are such that call( _Pred_, _A1_, _A2_, _A3_)
holds for every corresponding element in lists L1, L2, and L3
class include/3 |
include( 2:Pred, + ListIn, ? ListOut)
Same as selectlist/3
class selectlist/3 |
selectlist(1:Pred, + ListIn, ? ListOut)
)
Creates ListOut of all list elements of ListIn that pass a given test
class selectlist/5 |
selectlist( 2:Pred, + ListIn, + ListInAux, ? ListOut, ? ListOutAux)
Creates ListOut and ListOutAux of all list elements of ListIn and ListInAux that pass the given test Pred
class selectlist/4 |
selectlist( 2:Pred, + ListIn, + ListInAux, ? ListOut)
Creates ListOut of all list elements of ListIn that pass the given test Pred using + ListInAux as an auxiliary element
class exclude/3 |
exclude( 2:Goal, + List1, ? List2)
Filter elements for which Goal fails True if List2 contains those elements Xi of List1 for which call(Goal, Xi)
fails
class partition/4 |
partition(1:Pred, + List1, ? Included, ? Excluded)
Filter elements of List1 according to Pred True if Included contains all elements for which call(Pred, X)
succeeds and Excluded contains the remaining elements
class partition/5 |
partition(2:Pred, + List1, ? Lesser, ? Equal, ? Greater)
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
class checklist/2 |
checklist( 1:Pred, + List)
Succeeds if the predicate Pred succeeds on all elements of List
class maplist/5 |
maplist(: Pred, ? L1, ? L2, ? L3, ? L4)
L1, L2, L3, and L4 are such that call( _Pred_, _A1_, _A2_, _A3_, _A4_)
holds for every corresponding element in lists L1, L2, L3, and L4
class maplist/6 |
maplist(: Pred, ? L1, ? L2, ? L3, ? L4, ? L5)
L1, L2, L3, L4 and L5 are such that call( _Pred_, _A1_, _A2_, _A3_, _A4_,_A5_)
holds for every corresponding element in lists L1, L2, L3, L4 and L5
class convlist/3 |
convlist(: Pred, + ListIn, ? ListOut)
A combination of maplist/3 and selectlist/3 : creates ListOut by applying the predicate Pred to all list elements on which Pred succeeds
ROK: convlist(Rewrite, OldList, NewList) is a sort of hybrid of maplist/3 and sublist/3 Each element of NewList is the image under Rewrite of some element of OldList, and order is preserved, but elements of OldList on which Rewrite is undefined (fails) are not represented Thus if foo(X,Y) :- integer(X), Y is X+1 then convlist(foo, [1,a,0,joe(99),101], [2,1,102])
class convlist/4 |
convlist(: Pred, ? ListIn, ?ExtraList, ? ListOut)
A combination of maplist/4 and selectlist/3 : ListIn, ListExtra, and ListOut are the sublists so that the predicate Pred succeeds
ROK: convlist(Rewrite, OldList, NewList) is a sort of hybrid of maplist/3 and sublist/3 Each element of NewList is the image under Rewrite of some element of OldList, and order is preserved, but elements of OldList on which Rewrite is undefined (fails) are not represented Thus if foo(X,Y) :- integer(X), Y is X+1 then convlist(foo, [1,a,0,joe(99),101], [2,1,102])
class mapnodes/3 |
mapnodes(+ Pred, + TermIn, ? TermOut)
Creates TermOut by applying the predicate Pred to all sub-terms of TermIn (depth-first and left-to-right order)
class checknodes/2 |
checknodes(+ Pred, + Term)
Succeeds if the predicate Pred succeeds on all sub-terms of Term (depth-first and left-to-right order)
class sumlist/4 |
sumlist(: Pred, + List, ? AccIn, ? AccOut)
Calls Pred on all elements of List and collects a result in Accumulator Same as fold/4
class sumnodes/4 |
sumnodes(+ Pred, + Term, ? AccIn, ? AccOut)
Calls the predicate Pred on all sub-terms of Term and collect a result in Accumulator (depth-first and left-to-right order)
class foldl/6 |
foldl(:Goal, +List, +V0, -V, +W0, -WN)
foldl(Goal, List1, List2, List3, V0, V)
%
Apply Goal plus five arguuments, three map to lists, two can be used as a difference_type
class oldl/5 |
class foldl/5 |
foldl(: Pred, + List1, + List2, ? AccIn, ? AccOut)
Calls Pred on all elements of List1 and List2 and collects a result in Accumulator Same as foldr/4
class foldl2/6 |
foldl2(: Pred, + List, ? X0, ? X, ? Y0, ? Y)
Calls Pred on all elements of List
and collects a result in X and Y
class foldl2/7 |
v
foldl2(: Pred, + List, ? List1, ? X0, ? X, ? Y0, ? Y)
Calls Pred on all elements of List and List1 and collects a result in X and Y
class foldl2/8 |
foldl2(: Pred, + List, ? List1, ? List2, ? X0, ? X, ? Y0, ? Y)
Calls Pred on all elements of List, List1 and List2 and collects a result in X and Y
class foldl3/9 |
foldl3(: Pred, + List1, ? List2, ? X0, ? X, ? Y0, ? Y, ? Z0, ? Z)
Calls Pred on all elements of List
and collects a result in X, Y and Z
class foldl4/11 |
foldl4(: Pred, + List1, ? List2, ? X0, ? X, ? Y0, ? Y, ? Z0, ? Z, ? W0, ? W)
Calls Pred on all elements of List
and collects a result in X, Y, Z and W