Page 1 of 1

remove-duplicates and if

Posted: Thu Dec 05, 2013 2:06 pm
by xvn
Hi,

currently I'm facing the following problem and I would be very glad, if anyone could help:
from the following list ((a b c) (a b c) (a b) (a b) (a) (a)) I want to remove all duplicates, except (a b c). The result should be the list ((a b c) (a b c) (a b) (a)).
As this function should operate on the first list, irrespective of the number of (a b c), (a b) or (a).
I tried the function "remove-duplicates", but I don't know how to adapt it so that (a b c) duplicates are not removed.

For any help I would be very grateful!

And please excuse any errors regarding my English...

Re: remove-duplicates and if

Posted: Fri Dec 06, 2013 4:53 am
by marcoxa
Your spec is not complete. Why do you want to keep (A B C) only? Do you want to keep the first? Do you want to keep all the (A B C)? Do you want to remove only the duplicates of length other than 3?

Assuming you want to keep all entries of length equal 3, here is a solution that should give you a hint about other cases"

Code: Select all

(remove-duplicates '((a b c) (a b c) (a b) (a b) (a) (a))
     :test (lambda (x y)
             (and (/= (length x) 3)
                  (/= (length y) 3)
                  (equal x y))))
Cheers
--
MA

Re: remove-duplicates and if

Posted: Sat Dec 07, 2013 12:10 pm
by xvn
Perfect, that's exactly what I was looking for! Thanks!