tags:

views:

145

answers:

1

How do you check, in elisp, if a list returns a value? so the following would return t:

(contains 3 '(1 2 3))

but

(contains 5 '(1 2 3))

would return nil.

+7  A: 

The function you need is 'member

For example:

(member 3 '(1 2 3))

It will return the tail of list whose car is element. While this is not strictly 't, any non-nil value is equivalent to true for a boolean operation. Also, 'member uses 'equal to test for equality, use 'memq for stricter equality (using 'eq).

freiksenet
For further details, see http://www.gnu.org/software/emacs/emacs-lisp-intro/html_node/List-Processing.html
Török Gábor