Logo

Programming-Idioms

History of Idiom 12 > diff from v113 to v114

Edit summary for version 114 by ff:
[Scheme] fff

Version 113

2020-04-26, 15:05:34

Version 114

2020-04-28, 19:31:52

Idiom #12 Check if list contains a value

Check if list contains a value x.
list is an iterable finite container.

Illustration

Idiom #12 Check if list contains a value

Check if list contains a value x.
list is an iterable finite container.

Illustration
Extra Keywords
array vector member membership
Extra Keywords
array vector member membership
Code
(define (contains list x)
        (if (null? list) #f)
        (if (equal? (car list) x) #t)
        (else (contains (cdr list) x))))
Code
(define (f i lst)
   (if (= i 0) (car lst)
       (f (- i 1) (cdr lst))))
Comments bubble
This is a custom implementation, use it if no built-in predicate is available in your Scheme environment.
Comments bubble
This is a custom implementation, use it if no built-in predicate is available in your Scheme environment.
Demo URL
http://repl.it/SIT
Demo URL
http://repl.it/SIT