获取Lisp列表中列表的索引 [英] Get index of list within list in Lisp

查看:291
本文介绍了获取Lisp列表中列表的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有这样的列表

((0 1 2) (3 4 5) (6 7 8) (0 3 6) (1 3 7) (2 4 8) (0 4 8) (2 4 6))

我想找到(0 3 6)的索引,是否有内置函数可以执行此操作?当搜索项本身是列表时,POSITION似乎不起作用.

And I want to find the index of (0 3 6), is there a built-in function to do this? POSITION doesn't seem to work when the search item is itself a list.

推荐答案

请参见 hyperspec . POSITION可以采用:test参数:

See hyperspec. POSITION can take a :test argument:


(position '(0 3 6)
          '((0 1 2) (3 4 5) (6 7 8) (0 3 6) (1 3 7) (2 4 8) (0 4 8) (2 4 6))
          :test #'equal))
3

顺便说一下,POSITION(以及其他序列操作)的默认测试是EQL.

The default test for POSITION (and other sequence operations) is EQL, by the way.

这篇关于获取Lisp列表中列表的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆