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)
?
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 #'equaltomember: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:
eqis too implementation-dependent and does not work as one probably wants on numbers and charactersequalandequalptraverse 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, andequalpin Common Lisp.The Right Way
Use
set-differenceinstead ofremove-if+member.