
% find a pair of elements in a list
pair(L,A,B) :- member(A,L), member(B,L), A \= B.

% find all pairs of elements in a list using findall
pairs(L, P) :- findall([A,B], pair(L,A,B), P).

% print all pairs of elements in a list using foreach
ppairs(L) :- pairs(L,P), foreach(member(E,P),format("~w~n",[E])).

% find all pairs of elements in a list using bagof
bpairs(L, P) :- bagof([A,B], pair(L,A,B), P).

% print all pairs of elements in a list using foreach
pbpairs(L) :- bpairs(L,P), foreach(member(E,P),format("~w~n",[E])).

