Schema built-in to check list contents

In Python, I can make "x in a list" to see if the list contains x. Is there any equivalent built into Scheme for this?

+5
source share
4 answers

R5RS and the standard R6RS library for define listsmemq , memvand member which can be used for this purpose.

+6
source

In the PLT scheme there is

(member whatever list)
(memv whatever list)
(memq whatever list)

from SRFI, which are used, respectively equal?, eqv?and eq?to verify equality. There are also a number of other library functions related to list searches:

Link to the list of PLT circuits

+6
(define (contains? l i)
  (if (empty? l) #f
      (or (eq? (first l) i) (contains? (rest l) i))))
+4

, , . , .

0
source

All Articles