listemailprologduplicatesprolog-findall

Removing duplicates from a list generated with Findall


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.


Solution

  • 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).