From Rosetta Code
Revision as of 07:39, 24 October 2011 by rosettacode>EMBee (→‎Lists as sets in common lisp: alternatives)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Lists as sets in common lisp

The common lisp entry says it forms sets from lists. Does it handle duplicates correctly? Does it ignore order i.e does the set 1,2,3,4 equal the set 3,2,4,1 when the lists that they are composed from has the elements originally in those different orders? I cannot tell from the examples given. --Paddy3118 18:31, 23 October 2011 (UTC)

No, it doesn't do either. As far as I can tell (speaking out of my week and half CL expertise, so take that with a grain of salt), the set operators in Common Lisp are more of a convenience than a serious application. Duplicate elements can be removed by remove-duplicates, and adding elements can use adjoin which is no-op if element is already in set. The normal list equality test (likely equal) will not ignore order, that's why I used subset tests in the example. --Ledrug 18:42, 23 October 2011 (UTC)
according to [1] the set functions assume no duplicates. duplicates may potentially lead to an error.
instead of lists, hash-tables could be used or a library like FSet.
CL-Containers also contains a set type.--eMBee 07:39, 24 October 2011 (UTC)