remove-duplicates and if

Discussion of Common Lisp

remove-duplicates and if

Postby xvn » Thu Dec 05, 2013 2:06 pm

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...
xvn
 
Posts: 2
Joined: Thu Dec 05, 2013 1:54 pm

Re: remove-duplicates and if

Postby marcoxa » Fri Dec 06, 2013 4:53 am

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
Marco Antoniotti
marcoxa
 
Posts: 69
Joined: Thu Aug 14, 2008 6:31 pm

Re: remove-duplicates and if

Postby xvn » Sat Dec 07, 2013 12:10 pm

Perfect, that's exactly what I was looking for! Thanks!
xvn
 
Posts: 2
Joined: Thu Dec 05, 2013 1:54 pm


Return to Common Lisp

Who is online

Users browsing this forum: logxor and 2 guests