From ok@atlas.otago.ac.nz  Fri Dec 15 02:05:12 2000
Received: from atlas.otago.ac.nz (atlas.otago.ac.nz [139.80.32.250])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id CAA28882
	for <prolog@swi.psy.uva.nl>; Fri, 15 Dec 2000 02:05:11 +0100 (MET)
Received: (from ok@localhost)
	by atlas.otago.ac.nz (8.9.3/8.9.3) id OAA25849;
	Fri, 15 Dec 2000 14:05:32 +1300 (NZDT)
Date: Fri, 15 Dec 2000 14:05:32 +1300 (NZDT)
From: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
Message-Id: <200012150105.OAA25849@atlas.otago.ac.nz>
To: prolog@swi.psy.uva.nl, ra27946@scs.ubbcluj.ro
Subject: Re:  [SWIPL] About Applying a predicate to all the elements of a list

Rastei Amelia Viorela <ra27946@scs.ubbcluj.ro> 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.)

