0

If I want to find whether (x 2) exists within a list containing ((x 2) (y 2) (z 2)) for example, how do I do this?

(member '(x 2) '((x 2) (y 2) (z 2))) 

returns NIL as does find

Thanks for the help

uselpa
  • 18,732
  • 2
  • 34
  • 52
JJS
  • 13
  • 1
  • 4
  • 3
    possible duplicate of [Test if array is inside a list in lisp](http://stackoverflow.com/questions/19287777/test-if-array-is-inside-a-list-in-lisp) – sds Jan 02 '14 at 15:35
  • 1
    possible duplicate of [how to test whether one list is a member of another](http://stackoverflow.com/questions/19612193/how-to-test-whether-one-list-is-a-member-of-another) – Joshua Taylor Jan 03 '14 at 18:27

1 Answers1

5
? (member '(x 2) '((x 2) (y 2) (z 2)) :test 'equal)
((X 2) (Y 2) (Z 2))

In Common Lisp, member uses eql as the default test, which does not work in this case.

See here for details regarding eq, eql, equal and equalp.

Community
  • 1
  • 1
uselpa
  • 18,732
  • 2
  • 34
  • 52