Exercise 186: Use contains? to define functions that search for "atom", "basic", and "zoo", respectively.
The contains function is supplied by the text
; String Los -> Boolean ; to determine whether l contains the string s (define (contains? s l) (cond [(empty? l) false] [else (or (string=? (first l) s) (contains? s (rest l)))]))
Answer
; String Los -> Boolean
; to determine whether l contains the string s
(define (contains? s l)
(cond
[(empty? l) false]
[else (or (string=? (first l) s)
(contains? s (rest l)))]))
; Los -> Boolean
; to determine whether l contains the string "atom"
(define (contains-atom l)
(contains? "atom" l))
; Los -> Boolean
; to determine whether l contains the string "basic"
(define (contains-basic l)
(contains? "basic" l))
; Los -> Boolean
; to determine whether l contains the string "zoo"
(define (contains-zoo l)
(contains? "zoo" l))
No comments:
Post a Comment