Disclaimer: This answer is just a more explicit version of the comment by @lurker for posterity.
First, how do you do the AND? One simple option is to use a bitwise AND:
and(A, B, R) :- R is A /\ B.
Now, what you want is as simple as:
?- maplist(and, [1, 0, 0, 1], [0, 1, 0, 1], L).
L = [0, 0, 0, 1].
What is this maplist
? Since SWI-Prolog's code is both available and easy to browse, you can look at the standard library definition:
maplist(Goal, List1, List2, List3) :-
maplist_(List1, List2, List3, Goal).
maplist_([], [], [], _).
maplist_([Elem1|Tail1], [Elem2|Tail2], [Elem3|Tail3], Goal) :-
call(Goal, Elem1, Elem2, Elem3),
maplist_(Tail1, Tail2, Tail3, Goal).
This is more general than you probably need. First, you don't need to pass and/3
to the predicate that you want to write, you can simply inline it. So, you will replace the call
with and
or just with the is
. Now you also won't need to reorder the arguments, so you don't need to have a predicate and a helper predicate.
There is so much code out there, it is a shame not to look at it and try to learn.