projog

3.111. maplist(X,Y) / maplist(X,Y,Z) - determines if a goal succeeds against elements of a list.

maplist(X,Y) succeeds if the goal X can be successfully applied to each elements of the list Y.

Examples

?- maplist(atom, []).

yes

?- maplist(atom, [a]).

yes

?- maplist(atom, [X]).

no

?- maplist(atom, [1]).

no

?- maplist(integer, [1]).

yes

?- maplist(atom, [a,a,a]).

yes

?- maplist(atom, [a,b,c]).

yes

?- maplist(atom, [1,b,c]).

no

?- maplist(atom, [a,2,c]).

no

?- maplist(atom, [a,b,3]).

no

?- maplist(atom, [a,2,3]).

no

?- maplist(atom, [1,b,3]).

no

?- maplist(atom, [1,2,c]).

no

?- maplist(atom, [1,2,3]).

no

?- maplist(>(0), [3,4,2,1]).

no

?- maplist(<(5), [3,4,2,1]).

no

?- maplist(<(0), [3,4,2,1]).

yes

?- maplist(>(5), [3,4,2,1]).

yes

?- maplist(>(5), [3,4,5,2,1]).

no

?- maplist(>=(5), [3,4,5,2,1]).

yes

?- maplist(>=(5), [3,4,5,2,1,6]).

no

?- maplist(>=(5), [6,3,4,5,2,1]).

no

?- maplist(>=(5), [3,4,5,6,2,1]).

no

?- maplist(=(p(W)), [p(1),p(2),p(3)]).

no

First argument must be an atom or structure. Second argument must be a list.

?- maplist(X, []).

no

?- maplist(atom, X).

no

maplist/3 applies the goal to pairs of elements from two lists.

?- maplist(=, [1,2,3], [1,2,3]).

yes

?- maplist(=, [1,2,3], [4,5,6]).

no

?- maplist(=, [1,2,3], [1,3,2]).

no

?- maplist(=, [X,2,3], [1,Y,Z]).
X = 1
Y = 2
Z = 3

yes

?- maplist(=, [1,2,3], X).
X = [1,2,3]

yes

?- maplist(=, X, [1,2,3]).
X = [1,2,3]

yes

Note: "checklist" is a synonym for "maplist".

?- checklist(atom, [a,b,c]).

yes

?- checklist(atom, [a,2,c]).

no

?- checklist(=, [1,2,3], [1,2,3]).

yes

?- checklist(=, [1,2,3], [4,5,6]).

no

p(a,X,Y) :- X=Y.
p(b,1,1).
p(b,2,2).
p(b,3,4).
p(c,1,1).
p(c,2,2).
p(c,3,4).
p(c,1,1).
p(c,2,2).
p(c,3,4).

?- maplist(p(a), [1,2,3], [1,2,3]).

yes

?- maplist(p(a), [1,2,3], [1,2,4]).

no

?- maplist(p(b), [1,2,3], [1,2,3]).

no

?- maplist(p(b), [1,2,3], [1,2,4]).

yes;

no

?- maplist(p(c), [1,2,3], [1,2,4]).

yes;

yes;

yes;

yes;

yes;

yes;

yes;

yes;

no

?- maplist(p(z), [1,2,3], [1,2,3]).

no

?- maplist(p(z), [], []).

yes

?- maplist(p(c,1), [1,1]).

yes;

yes;

yes;

yes

?- maplist(append, [[a,b],[c,d]], [[1,2],[3,4]], X).
X = [[a,b,1,2],[c,d,3,4]]

yes

?- maplist(append, X, Y, [[a,b,c,d],[1,2,3,4]]).
X = [[],[]]
Y = [[a,b,c,d],[1,2,3,4]]

yes;
X = [[],[1]]
Y = [[a,b,c,d],[2,3,4]]

yes;
X = [[],[1,2]]
Y = [[a,b,c,d],[3,4]]

yes;
X = [[],[1,2,3]]
Y = [[a,b,c,d],[4]]

yes;
X = [[],[1,2,3,4]]
Y = [[a,b,c,d],[]]

yes;
X = [[a],[]]
Y = [[b,c,d],[1,2,3,4]]

yes;
X = [[a],[1]]
Y = [[b,c,d],[2,3,4]]

yes;
X = [[a],[1,2]]
Y = [[b,c,d],[3,4]]

yes;
X = [[a],[1,2,3]]
Y = [[b,c,d],[4]]

yes;
X = [[a],[1,2,3,4]]
Y = [[b,c,d],[]]

yes;
X = [[a,b],[]]
Y = [[c,d],[1,2,3,4]]

yes;
X = [[a,b],[1]]
Y = [[c,d],[2,3,4]]

yes;
X = [[a,b],[1,2]]
Y = [[c,d],[3,4]]

yes;
X = [[a,b],[1,2,3]]
Y = [[c,d],[4]]

yes;
X = [[a,b],[1,2,3,4]]
Y = [[c,d],[]]

yes;
X = [[a,b,c],[]]
Y = [[d],[1,2,3,4]]

yes;
X = [[a,b,c],[1]]
Y = [[d],[2,3,4]]

yes;
X = [[a,b,c],[1,2]]
Y = [[d],[3,4]]

yes;
X = [[a,b,c],[1,2,3]]
Y = [[d],[4]]

yes;
X = [[a,b,c],[1,2,3,4]]
Y = [[d],[]]

yes;
X = [[a,b,c,d],[]]
Y = [[],[1,2,3,4]]

yes;
X = [[a,b,c,d],[1]]
Y = [[],[2,3,4]]

yes;
X = [[a,b,c,d],[1,2]]
Y = [[],[3,4]]

yes;
X = [[a,b,c,d],[1,2,3]]
Y = [[],[4]]

yes;
X = [[a,b,c,d],[1,2,3,4]]
Y = [[],[]]

yes

nine_arg_predicate(V1,V2,V3,V4,V5,V6,V7,V8,V9) :-
write(V1), write(' '),
write(V2), write(' '),
write(V3), write(' '),
write(V4), write(' '),
write(V5), write(' '),
write(V6), write(' '),
write(V7), write(' '),
write(V8), write(' '),
write(V9), nl.

?- maplist(nine_arg_predicate(1,2,3,4,5,6,7,8),[q,w]).
1 2 3 4 5 6 7 8 q
1 2 3 4 5 6 7 8 w

yes

?- maplist(nine_arg_predicate(1,2,3,4,5,6,7),[q,w],[e,r]).
1 2 3 4 5 6 7 q e
1 2 3 4 5 6 7 w r

yes

?- maplist(nine_arg_predicate(1,2,3,4,5,6),[q,w],[e,r],[t,y]).
1 2 3 4 5 6 q e t
1 2 3 4 5 6 w r y

yes

?- maplist(nine_arg_predicate(1,2,3,4,5),[q,w],[e,r],[t,y],[u,i]).
1 2 3 4 5 q e t u
1 2 3 4 5 w r y i

yes

?- maplist(nine_arg_predicate(1,2,3,4),[q,w],[e,r],[t,y],[u,i],[o,p]).
1 2 3 4 q e t u o
1 2 3 4 w r y i p

yes

?- maplist(nine_arg_predicate(1,2,3),[q,w],[e,r],[t,y],[u,i],[o,p],[a,s]).
1 2 3 q e t u o a
1 2 3 w r y i p s

yes

?- maplist(nine_arg_predicate(1,2),[q,w],[e,r],[t,y],[u,i],[o,p],[a,s],[d,f]).
1 2 q e t u o a d
1 2 w r y i p s f

yes

?- maplist(nine_arg_predicate(1),[q,w],[e,r],[t,y],[u,i],[o,p],[a,s],[d,f],[g,h]).
1 q e t u o a d g
1 w r y i p s f h

yes

?- maplist(nine_arg_predicate,[q,w],[e,r],[t,y],[u,i],[o,p],[a,s],[d,f],[g,h],[j,k]).
q e t u o a d g j
w r y i p s f h k

yes

?- checklist(nine_arg_predicate(1,2,3,4,5,6,7,8),[q,w]).
1 2 3 4 5 6 7 8 q
1 2 3 4 5 6 7 8 w

yes

?- checklist(nine_arg_predicate(1,2,3,4,5,6,7),[q,w],[e,r]).
1 2 3 4 5 6 7 q e
1 2 3 4 5 6 7 w r

yes

?- checklist(nine_arg_predicate(1,2,3,4,5,6),[q,w],[e,r],[t,y]).
1 2 3 4 5 6 q e t
1 2 3 4 5 6 w r y

yes

?- checklist(nine_arg_predicate(1,2,3,4,5),[q,w],[e,r],[t,y],[u,i]).
1 2 3 4 5 q e t u
1 2 3 4 5 w r y i

yes

?- checklist(nine_arg_predicate(1,2,3,4),[q,w],[e,r],[t,y],[u,i],[o,p]).
1 2 3 4 q e t u o
1 2 3 4 w r y i p

yes

?- checklist(nine_arg_predicate(1,2,3),[q,w],[e,r],[t,y],[u,i],[o,p],[a,s]).
1 2 3 q e t u o a
1 2 3 w r y i p s

yes

?- checklist(nine_arg_predicate(1,2),[q,w],[e,r],[t,y],[u,i],[o,p],[a,s],[d,f]).
1 2 q e t u o a d
1 2 w r y i p s f

yes

?- checklist(nine_arg_predicate(1),[q,w],[e,r],[t,y],[u,i],[o,p],[a,s],[d,f],[g,h]).
1 q e t u o a d g
1 w r y i p s f h

yes

?- checklist(nine_arg_predicate,[q,w],[e,r],[t,y],[u,i],[o,p],[a,s],[d,f],[g,h],[j,k]).
q e t u o a d g j
w r y i p s f h k

yes