Now ** =..** is pronounced ``univ''.
It can be used to map a term onto a list in this way:

Term [ Functor, Arg, Arg, ... Arg]For example,

The predicate can also be used with?- foo(12,fred)=.. [foo,12,fred].yes

?- fact(male(fred),23)=.. X

X= [fact,male(fred),23]

Here are some more examples:?- X=.. [fact,male(fred),23].X = fact(male(fred),23)

We demonstrate a real application where we have a predicate?- (a + b) =.. X.X = [+, a, b]

?- [a,b,c] =.. X.

X = ['.',a,[b,c]]

We give the special case with the first argument as triple and then generalise it.?- map(triple,[1,2,3],X).X=[3,6,9]

The main trick is to assemble a term looking likemap(triple,[],[]).map(triple,[H1T1],H2T2]):-

X=.. [triple,H1,H2],

call(X),

map(triple,T1,T2).

Now we replace the specific reference to ** triple**
and provide a more general version that can handle
the task for arbitrary predicates of arity 2 ---provided
that they are defined to work with ** mode predname(+,-)**.

The next task is to allow for an even more general version that can do the same sort of thing for predicates with an arity of more than two!map(Functor,[],[]).map(Functor,[H1T1],H2T2]):-

X=.. [Functor,H1,H2],

call(X),

map(Functor,T1,T2).

For example, define a predicate ** npl/3**
that takes a positive integer as first argument and a number
as its second argument, returning the third argument
as the second argument `npled' as in:

We define?- nple(7,5,X).X=35

Now to look at the code. Now, we need to give the new version ofnple(Multiplier,In,Out):- Out is Multiplier*In. [-5pt]

We can do this as the term ** nple(N)** where ** N** is the multiplier.
We transform the term ** nple(N)** into a list ** [nple,N]**
and then append the two arguments ** H1** and ** H2** using the standard
** append/3**. This list
is then rebuilt as the term ** nple(N,H1,H2)** and then executed via ** call/1**.

Nowhere does this really depend on the arity ofmap(nple(N),[],[]).map(nple(N),[H1T1],[H2T2]):-

nple(N)=.. List,

append(List,[H1,H2],NewList),

X=.. NewList,

call(X),

map(nple(N),T1,T2).

map(Term,[],[]).map(Term,[H1T1],[H2T2]):-

Term=.. List,

append(List,[H1,H2],NewList),

X=.. NewList,

call(X),

map(Term,T1,T2).

Mon May 24 20:14:48 BST 1999