Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!news.mathworks.com!news.ultranet.com!news.sprintlink.net!EU.net!Germany.EU.net!Munich.Germany.EU.net!ecrc!acrab60!thom
From: thom@ecrc.de (Thom Fruehwirth)
Subject: Re: Help with Subset Function
Message-ID: <D5L5Lo.LHt@ecrc.de>
Sender: news@ecrc.de
Reply-To: thom@ecrc.de
Organization: European Computer-Industry Research Centre GmbH.
References: <3kbage$bpu@goanna.cs.rmit.edu.au>
Date: Fri, 17 Mar 1995 13:03:23 GMT
Lines: 19

Richard A. O'Keefe wrote:

	subset([], _).
	subset([X|Xs], Ys) :-
	    member(X, Ys),
	    subset(Xs, Ys).

	Please note, however, that this representation of sets is woefully
	inefficient in _any_ programming language.  A better representation is
	as a sorted (in the sense of sort/2) list with no duplicates.



Please note that you'll have to rewrite subset/2 for sorted lists,
because the predicate member/2 will usually be *slower* on sorted
lists due to the additional comparisons.

thom

