Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lisp list-contains program

Tags:

common-lisp

how can I make a Lisp program that checks if a character, string or number is in a list?

(list-contains '(1 a 2 d 2 5) 'a) => T

(list-contains '(1 a 2 d 2 5) 'x) => NIL

like image 867
sebastian Avatar asked Nov 30 '22 10:11

sebastian


1 Answers

You can use (find x the-list) which returns x if x is in the list or NIL if it is not.

(find 'a '(1 a 2 d 2 5)) ; A
(find 'x '(1 a 2 d 2 5)) ; NIL
like image 93
sepp2k Avatar answered Dec 05 '22 01:12

sepp2k