Can anybody explain to me why this:
(remove-if #'(lambda (var) (member var (list "x"))) (list "x" "y" "z"))
returns this:
("x" "y" "z")
but this:
(remove-if #'(lambda (var) (member var (list 1))) (list 1 2 4))
returns this:
(2 4)
?
The Answer
Pass
:test #'equal
tomember
:Note that
The Reason
The default One-Argument Test in Common Lisp is
eql
.It is the most reasonable choice between the 4(!) general purpose comparison functions provided for by the ANSI CL standard:
eq
is too implementation-dependent and does not work as one probably wants on numbers and charactersequal
andequalp
traverse objects and thus take a long time for huge ones and may never terminate for circular ones.See also the difference between
eq
,eql
,equal
, andequalp
in Common Lisp.The Right Way
Use
set-difference
instead ofremove-if
+member
.