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

From: Rastei Amelia Viorela <[email-masked]>
Date: Fri, 15 Dec 2000 09:48:08 +0200 (EET)

I thank Richard O'Keefe and Nicos and Jan and Dmitry for
all their useful information.
     It really helps me.

     Best regards,

     Amelia.

On Fri, 15 Dec 2000, Richard A. O'Keefe wrote:

> Rastei Amelia Viorela <[email-masked]> wrote:
> > Sorry, previous question was not clear at all!
> > I reformulate:
> > How does maplist actually work? 
> 	
> You don't need to know that.
> What you need to know is what it *means*.
> 
> The maplist/N family of predicates, designed by Lawrence Byrd and me,
> can be explained as
> 
>     maplist(P, [X11,...,X1n], ..., [Xm1,...,Xmn]) :-
> 	P(X11, ..., Xm1),
> 	...
> 	P(Xm1, ..., Xmn).
> 
> For the sake of argument, let's invent an :- index declaration, which
> says to build indices on each of the specified arguments independently,
> and to use the first one in numerical order for which the actual argument
> is non-variable.  Then we'd have
> 
>     :- index maplist(_,1).
> 
>     maplist(P, []).
>     maplist(P, [X1|X1s]) :-
>         call(P, X1),
>         maplist(P, X1s).
> 
>     :- index maplist(_,1,2).
> 
>     maplist(P, [], []).
>     maplist(P, [X1|X1s], [X2|X2s]) :-
>         call(P, X1, X2),
>         maplist(P, X1s, X2s).
> 
>     :- index maplist(_,1,2,3).
> 
>     maplist(P, [], [], []).
>     maplist(P, [X1|X1s], [X2|X2s], [X3|X3s]) :-
>         call(P, X1, X2, X3),
>         maplist(P, X1s, X2s, X3s).
> 
> 
> As for the call/N family (invented by me and Alan Mycroft),
> it's defined *as if*
> 
>     call(P(X1,...,Xm), Y1, ..., Yn) :- P(X1, ..., Xm, Y1, ..., Yn).
> 
> There are many ways to implement that, some faster than others.
> 
> 	    I am trying to implement MINIMAX algotithm. For Tic tac Toe.
> 
> Is that the same as noughts and crosses?
> 
> The important thing is that the first argument of call/(N+1) or
> maplist/(N+1) is a callable term representing a call to a predicate
> that is missing the *last* N arguments.  (Why the last?  Because of
> the general inputs-before-outputs style rule in Prolog.)
> 

-- 

 Amelia Rastei,
 Dept. Computer Science,
 Babes Bolyai University,
 Cluj Napoca, Romania.