Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!delmarva.com!news.internetMCI.com!newsfeed.internetmci.com!EU.net!Germany.EU.net!Frankfurt.Germany.EU.net!Munich.Germany.EU.net!ecrc!acrab60!thom
From: thom@ecrc.de (Thom Fruehwirth)
Subject: Re: Duplicates from a list
Message-ID: <DI2z9D.Hxz@ecrc.de>
Sender: news@ecrc.de
Reply-To: thom@ecrc.de
Organization: European Computer-Industry Research Centre GmbH.
References: <488k57$4pi@mailman.xilinx>
Date: Wed, 15 Nov 1995 10:46:25 GMT
Lines: 32

On 13 Nov 1995 23:25:27 GMT <douglash> wrote:

member(M,[M|_]).
member(M,[_|T]):- member(M,T).

dupes([],A,A).
dupes([H|T],A,L):- 
   member(H,T),		%quintus doesn't have builtin member
   append([H],A,List), 	%builtin
   dupes(T,List,L).	
dupes([_|T],A,L) :- dupes(T,A,L).


-------

To get the elements of a list with more than one occurence,
one doesn't need append/3 or an accumulator argument:

dup([],[]).
dup([H|T],[H|L]):- 
   member(H,T),	
   !,	
   dup(T,L).	
dup([_|T],L) :- 
   dup(T,L).



---
thom
http://www.ecrc.de/staff/thom/

