(and (consp (cdr x))
(cons (car x) (butlast (cdr x)))))
-(defun member (x list)
+(defun member (x list &key (key #'identity) (test #'eql))
(while list
- (when (eql x (car list))
+ (when (funcall test x (funcall key (car list)))
(return list))
(setq list (cdr list))))
(test (not (assoc 2 alist)))
(test (not (rassoc 1 alist))))
+; MEMBER
+(test (equal (member 2 '(1 2 3)) '(2 3)))
+(test (not (member 4 '(1 2 3))))
+(test (equal (member 4 '((1 . 2) (3 . 4)) :key #'cdr) '((3 . 4))))
+(test (member '(2) '((1) (2) (3)) :test #'equal))
+
; SUBST
; Can't really test this until EQUAL works properly on lists