1
votes

I have a predicate which checks for duplicates in a list and returns true if there are no duplicates and false if there are duplicates present:

removeDups([], []).
removeDups([H|T], [H|T1]) :- subtract(T, [H], T2), removeDups(T2, T1).

I want to write another predicate that will basically check if removeDups successfully removes duplicates from a list whilst leaving the other list items present still. So for example a predicate testRemoveDuplicates/1 where the input is a list. I'm not sure how to go about doing this though.

Thanks in advance.

1

1 Answers

0
votes

remove_dups(+List, ?Pruned) Sicstus

removes duplicated elements from List, which should be a proper list.

test

| ?- remove_dups([item0,item1,item0,item2,item3,item4,item2], Pruned).
Pruned = [item0,item1,item2,item3,item4] ? ;
no
% source_info
| ?- remove_dups([item0,item1,item0,item2,item3,item4,item2], [item0,item1,item2,item3,item4]).
yes

if you want to integrate your predicat then

testRemoveDuplicates(ListResult) :- removeDups(ListResult,ListResult).