比较/交叉点列表

发布于 2025-02-03 09:09:46 字数 391 浏览 2 评论 0 原文

我想使用 查看两个列表的交集。

虽然

(intersection (list 1 1) (list 1 1))

效果很好,并且返回(1 1),但

 (intersection (list (list 1 2) (list 1 4)) (list (list 1 2) (list 1 5)))

不返回我(1 2),而是零。

我的错误在哪里?

I wanted to use intersection
to see the intersection of two lists.

While

(intersection (list 1 1) (list 1 1))

works perfectly fine and returns (1 1),

 (intersection (list (list 1 2) (list 1 4)) (list (list 1 2) (list 1 5)))

doesnt return me (1 2) but NIL.

Where is my mistake?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在梵高的星空下 2025-02-10 09:09:46

交叉点 :test 关键字参数指定要使用的“平等”的定义。默认值为它比较指针平等的列表。由于您的两个列表实际上是内存中的不同列表,因此它们不是 eql 。使用元素。

  (intersection (list (list 1 2) (list 1 4)) (list (list 1 2) (list 1 5)) :test #'equal)

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 to compare lists element-wise.

  (intersection (list (list 1 2) (list 1 4)) (list (list 1 2) (list 1 5)) :test #'equal)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文