Removing duplicates from a list generated with Findall

3.1k views Asked by At

I'm practicing Prolog by coming up with a very simple database of who has sent and received emails.

I have created a list using findall of the receivers of a pre-specified X.

1

There are 1 answers

3
CapelliC On BEST ANSWER

to use your list/2:

all_receivers(X,Uniques) :- findall(Y,(email(X,Y)),List),list(List,Uniques).

but the easiest way is sort/2, or better setof/3

all_receivers(X,List) :- setof(Y,X^(email(X,Y)),List).