
% removeDups(L,R)
% ---------------
% succeeds iff list R is list L with all duplicates removed

% base case, nothing to do
removeDups([], []).

% if the front element also appears later in the list
%    then don't include it in the result yet,
%    go on and process the rest of the list
removeDups([H|T], R) :- member(H,T), removeDups(T,R).

% if we get here then the front element wasn't in the list, so
%    include it in the result and process the rest of the list
removeDups([H|T], [H|R]) :- removeDups(T,R).
 
