From 227c815341a7956c3bfff6b93f406c0d7b8cefb7 Mon Sep 17 00:00:00 2001 From: Ken Harris Date: Sat, 15 Jun 2013 21:59:00 -0700 Subject: [PATCH] Bug fix: INTERSECTION doesn't apply :key to list1. --- src/list.lisp | 2 +- tests/list.lisp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/list.lisp b/src/list.lisp index 6b58aae..dabd201 100644 --- a/src/list.lisp +++ b/src/list.lisp @@ -317,6 +317,6 @@ (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)) diff --git a/tests/list.lisp b/tests/list.lisp index ac6ae90..4a99d8c 100644 --- a/tests/list.lisp +++ b/tests/list.lisp @@ -191,6 +191,9 @@ (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)) -- 1.7.10.4