任何人都可以向我解释原因:
(remove-if #'(lambda (var) (member var (list "x"))) (list "x" "y" "z"))
返回:
("x" "y" "z")
但是这个:
(remove-if #'(lambda (var) (member var (list 1))) (list 1 2 4))
返回:
(2 4)
答案 0 :(得分:4)
将:test #'equal
传递给member
:
(remove-if #'(lambda (var) (member var (list "x") :test #'equal)) (list "x" "y" "z"))
==> ("y" "z")
请注意
(eql "x" "x")
==> NIL
(equal "x" "x")
==> T
(eql 1 1)
==> T
默认One-Argument Test in Common Lisp is eql
。
这是ANSI CL标准提供的4(!)通用比较功能之间最合理的选择:
另见the difference between eq
, eql
, equal
, and equalp
in Common Lisp。
使用set-difference
代替remove-if
+ member
。