Compare/Intersection 列表列表
Compare/Intersection List of Lists
我想用 intersection
查看两个列表的交集。
同时
(intersection (list 1 1) (list 1 1))
工作得很好并且 returns (1 1)
,
(intersection (list (list 1 2) (list 1 4)) (list (list 1 2) (list 1 5)))
没有 return 我 (1 2) 但 NIL。
我的错误在哪里?
intersection
takes an optional :test
keyword argument to specify what definition of "equality" to use. The default is eql
, which compares lists for pointer equality. Since your two lists are actually distinct lists in memory, they're not eql
. Use equal
比较列表 element-wise。
(intersection (list (list 1 2) (list 1 4)) (list (list 1 2) (list 1 5)) :test #'equal)
我想用 intersection
查看两个列表的交集。
同时
(intersection (list 1 1) (list 1 1))
工作得很好并且 returns (1 1)
,
(intersection (list (list 1 2) (list 1 4)) (list (list 1 2) (list 1 5)))
没有 return 我 (1 2) 但 NIL。
我的错误在哪里?
intersection
takes an optional :test
keyword argument to specify what definition of "equality" to use. The default is eql
, which compares lists for pointer equality. Since your two lists are actually distinct lists in memory, they're not eql
. Use equal
比较列表 element-wise。
(intersection (list (list 1 2) (list 1 4)) (list (list 1 2) (list 1 5)) :test #'equal)