I need construct a predicate who receive a list, check who are the repeated elements and return other list with them. Example:
?- rep_elements([a,b,c,a,b,d], Xs).
Xs = [a,b].
I start building a basic structure, but I don't now how to finish this predicate, or if this it the better way:
exists(Elem, [Elem|_]).
exists(Elem, [H|T]) :-
exists(Elem, T).
rep_elements([], []).
rep_elements([H|T], [Y|Z]) :-
exists(H, T),
rep_elements(T, Z).
Any suggestions?