0
votes

Let say I have a list [[a,b,c],[d,e,f],[g,h,i]]

I want to get every consecutive element and put it in another predicate.

func(a,b).
func(b,c).

func(d,e).
func(e,f).

func(g,h).
func(h,i).

I already wrote the predicate I want to put in, but I'm having a hard time getting two elements from the list of lists.

1
Just flatten/2 list to ease taking out two cons. elements as @joel76 suggestedony

1 Answers

1
votes

You can try :

consecutive(L, R) :-
    maplist(create_func, L, RT),
    flatten(RT, R).

create_func([A,B], [func(A,B)]) :- !.

create_func([A,B | T], [func(A,B) | R]) :-
    create_func([B | T], R).