Reputation: 229461
In Python I can do "x in list" to see if the list contains x. Is there any equivalent built-in in Scheme to do this?
Upvotes: 5
Views: 14919
Reputation: 1208
The R5RS, and the R6RS standard library for lists
define memq
, memv
, and member
which can be used for that purpose.
Upvotes: 7
Reputation: 71985
In PLT Scheme, one has
(member whatever list)
(memv whatever list)
(memq whatever list)
from the SRFI which use, respectively, equal?
, eqv?
, and eq?
to test for equality. There are also a number of other library functions related to searching in lists:
Upvotes: 6
Reputation: 229461
(define (contains? l i)
(if (empty? l) #f
(or (eq? (first l) i) (contains? (rest l) i))))
Upvotes: 4
Reputation: 181350
No, there is no list built-in predicate that will do that for you. It's extremely easy to define a lambda or a macro to do just that though.
Upvotes: 0