## clisp-list

 [clisp-list] Remove duplicates from a complex list From: Justice, Randy -CONT(DYN) - 2001-10-27 14:27:14 Attachments: Message as HTML Hi. I'm trying to remove duplicates from a list. I have defined the following function: (defun noduplicates (list) (let ((set ())) (mapc #'(lambda (x) (setq set (adjoin x set :test #'equal))) list) set)) [17]> (setq b '( 1 2 3 4 5 1 2 3)) (1 2 3 4 5 1 2 3) [18]> (noduplicates b) (5 4 3 2 1) [19]> (setq b '( (1) (2) (3) (4) (5) (1) (2) (3))) ((1) (2) (3) (4) (5) (1) (2) (3)) [20]> (noduplicates b) ((5) (4) (3) (2) (1)) [21]> (setq b '( (1 1) (2 1) (3 1) (4 1) (5 1) (1 1) (2 1) (3 1))) ((1 1) (2 1) (3 1) (4 1) (5 1) (1 1) (2 1) (3 1)) [22]> (noduplicates b) ((5 1) (4 1) (3 1) (2 1) (1 1)) As you can see it works for "simple" lists... When it comes to a more complex lists it does not work... (setq z '((#3A(((3 4 0) (1 3 2) (1 3 2)) ((1 0 4) (4 0 0) (4 3 1)) ((2 1 0) (0 1 1) (0 3 3))) (0 1915)) (#3A(((0 2 1) (3 3 4) (3 4 0)) ((1 3 2) (3 3 1) (0 2 2)) ((3 1 4) (0 2 2) (1 4 1))) (0 1917)) (#3A(((2 4 0) (4 3 1) (4 1 0)) ((2 2 1) (4 3 0) (0 3 3)) ((1 2 0) (0 1 0) (0 2 2))) (0 2017)) (#3A(((3 4 0) (1 3 2) (1 3 2)) ((1 0 4) (4 0 0) (4 3 1)) ((2 1 0) (0 1 1) (0 3 3))) (0 1915)) (#3A(((3 4 0) (1 3 2) (1 3 2)) ((1 0 4) (4 0 0) (4 3 1)) ((2 1 0) (0 1 1) (0 3 3))) (0 1915))) ) [74]> (noduplicates z) ((#3A(((3 4 0) (1 3 2) (1 3 2)) ((1 0 4) (4 0 0) (4 3 1)) <== Duplicate ((2 1 0) (0 1 1) (0 3 3))) (0 1915)) (#3A(((3 4 0) (1 3 2) (1 3 2)) ((1 0 4) (4 0 0) (4 3 1)) <== Duplicate ((2 1 0) (0 1 1) (0 3 3))) (0 1915)) (#3A(((2 4 0) (4 3 1) (4 1 0)) ((2 2 1) (4 3 0) (0 3 3)) ((1 2 0) (0 1 0) (0 2 2))) (0 2017)) (#3A(((0 2 1) (3 3 4) (3 4 0)) ((1 3 2) (3 3 1) (0 2 2)) ((3 1 4) (0 2 2) (1 4 1))) (0 1917)) (#3A(((3 4 0) (1 3 2) (1 3 2)) ((1 0 4) (4 0 0) (4 3 1)) <== Duplicate ((2 1 0) (0 1 1) (0 3 3))) (0 1915))) [75]> What's going on?? How do I remove the duplicates from the list? Randy
 Re: [clisp-list] Remove duplicates from a complex list From: Sam Steingold - 2001-10-27 15:36:46 > * In message > * On the subject of "[clisp-list] Remove duplicates from a complex list" > * Sent on Sat, 27 Oct 2001 09:27:40 -0500 > * Honorable "Justice, Randy -CONT\(DYN\)" writes: > > I'm trying to remove duplicates from a list. CLHS has DELETE-DUPLICATES and REMOVE-DUPLICATES > (defun noduplicates (list) > (let ((set ())) > (mapc #'(lambda (x) > (setq set (adjoin x set :test #'equal))) > list) > set)) > (setq z '((#3A(((3 4 0) (1 3 2) (1 3 2)) > ((1 0 4) (4 0 0) (4 3 1)) > ((2 1 0) (0 1 1) (0 3 3))) > (0 1915)) > (#3A(((0 2 1) (3 3 4) (3 4 0)) > ((1 3 2) (3 3 1) (0 2 2)) > ((3 1 4) (0 2 2) (1 4 1))) > (0 1917)) read about EQ, EQL, EQUAL and EQUALP in CLHS. (equal #(1 2 3) #(1 2 3)) ==> nil (equalp #(1 2 3) #(1 2 3)) ==> t -- Sam Steingold (http://www.podval.org/~sds) Keep Jerusalem united! ; Read, think and remember! ; ; Parachute for sale, once used, never opened, small stain.