Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get index of list within list in Lisp

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.

like image 546
Jason Swett Avatar asked Nov 26 '10 20:11

Jason Swett


1 Answers

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.

like image 150
Nietzche-jou Avatar answered Nov 15 '22 06:11

Nietzche-jou