Subject: Re: [SWIPL] About Applying a predicate to all the elements of a list

From: Jan Wielemaker <[email-masked]>
Date: Thu, 14 Dec 2000 15:15:26 +0100

>     Sorry, previous question was not clear at all!
> 
>     I reformulate:
>   
>     How does maplist actually work? 

?- edit(maplist).

gives:

%	maplist(+Goal, +List1, ?List2)
%	True if Goal can succesfully be applied to all succesive pairs
%	of elements of List1 and List2.

maplist(Goal, List1, List2) :-
	maplist2(List1, List2, Goal).

maplist2([], [], _).
maplist2([Elem1|Tail1], [Elem2|Tail2], Goal) :-
	call(Goal, Elem1, Elem2), 
	maplist2(Tail1, Tail2, Goal).

So, maplist maintains a relation defined by Goal between successive
elements of the two lists.

For those interested, using maplist doesn't make your programs faster.
If you are in a hurry, simply write the loop yourself.  The trouble
is call/3, performing a rather expensive meta-call.

	--- Jan