Get index of list within list in Lisp

早过忘川 提交于 2019-12-21 12:12:41

问题


If I have a list like this

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

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.


回答1:


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

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



来源:https://stackoverflow.com/questions/4288292/get-index-of-list-within-list-in-lisp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!