Bug fix: INTERSECTION doesn't apply :key to list1.
authorKen Harris <kengruven@gmail.com>
Sun, 16 Jun 2013 04:59:00 +0000 (21:59 -0700)
committerKen Harris <kengruven@gmail.com>
Sun, 16 Jun 2013 04:59:00 +0000 (21:59 -0700)
src/list.lisp
tests/list.lisp

index 6b58aae..dabd201 100644 (file)
 (defun intersection (list1 list2 &key (test #'eql) (key #'identity))
   (let ((new-list ()))
     (dolist (x list1)
-      (when (member x list2 :test test :key key)
+      (when (member (funcall key x) list2 :test test :key key)
         (push x new-list)))
     new-list))
index ac6ae90..4a99d8c 100644 (file)
 (test (equal (intersection '(1 2) '(2 3)) '(2)))
 (test (not (intersection '(1 2 3) '(4 5 6))))
 (test (equal (intersection '((1) (2)) '((2) (3)) :test #'equal) '((2))))
+(test (equal '((1 . 2))
+             (intersection '((1 . 2) (2 . 3)) '((9 . 2) (9 . 4))
+                           :test #'equal :key #'cdr)))
 
 ; POP
 (test (let* ((foo '(1 2 3))