7

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 Answer 1

14

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Curiously, the CLHS page for FIND links to "Rules about Test Functions", but the page for POSITION doesn't. Here's where the default of EQL is documented: lispworks.com/documentation/HyperSpec/Body/17_ba.htm
sorry but which language should i choose in DrRacket to run this code @Nietzche-jou

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.