I have a list called X and I am trying to iterate through the list, I have a separate list Y where the elements of Y are (U,V) where U is X+1 and V is X-1. I have been trying to append U and V to Y with no success. SO it should work such that if X is [4,5,6] Y will be [(3,5),(4,6),(5,7)]
/**
list_looping([], _).
list_looping([H|T],A) :-
x is H-1,
x is H+1,
append([(x,y),T],A).
pairs([],[]).
pairs([H|T],[(U,V),L]):-
list_looping([H|T],[(U,V),L]).
*/
pairs(X,Y) :-
forall(member(X,[1,2,3]),((U is X+1,V is X-1),writeln((U,V)))).
I have tried two different implementations, in the first I am trying to recursively search through the list, with little success. In the second I am trying to use Prolog's inbuilt forall function, this obviously doesn't work either.