Giuspex
Giuspex

Reputation: 3

List Transformation

I have a list:

L = [1,2,3,4,5,6,7,8]

I would like to transform it into this:

L= [ex(1,2),ex(3,4),ex(5,6),ex(7,8)]

How can I effectively do this?

[edited to add:] This is what I have so far:

convert( [] , S ) .
convert( [A,B|Rest] , S ) :-
  S is ( ex(A,B) | Rest ) ,
  convert(Rest)
  . 

Upvotes: 0

Views: 64

Answers (1)

Daniel Lyons
Daniel Lyons

Reputation: 22803

Gosh, have you tried anything at all?

convert([], []).
convert([X,Y|R], [ex(X,Y)|S]) :- convert(R, S).

Tell your prof I said "hi".

Upvotes: 1

Related Questions