From jan@swi.psy.uva.nl  Thu Dec 14 15:15:36 2000
Received: from gollem.swi.psy.uva.nl (gollem [145.18.152.30])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id PAA09591;
	Thu, 14 Dec 2000 15:15:36 +0100 (MET)
Received: (from jan@localhost)
	by gollem.swi.psy.uva.nl (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id PAA14549;
	Thu, 14 Dec 2000 15:15:26 +0100
Date: Thu, 14 Dec 2000 15:15:26 +0100
Message-Id: <200012141415.PAA14549@gollem.swi.psy.uva.nl>
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Subject: Re: [SWIPL] About Applying a predicate to all the elements of a list
To: Rastei Amelia Viorela <ra27946@scs.ubbcluj.ro>, prolog@swi.psy.uva.nl
In-Reply-To: Rastei Amelia Viorela's message of Thu, 14 Dec 2000 15:28:29 +0200 (EET)
Phone: +31 - 20 - 525 6121

>     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

