Here is a solution to contains-milk? that we were working on at the end of class today:
;; contains-milk?: list-of-string -> boolean ;; determines whether the list contains milk (define (contains-milk? alos) (cond [(empty? alos) false] [(cons? alos) (cond [(string=? "milk" (first alos)) true] [else (contains-milk? (rest alos))])]))An alternative way to write the function is like this:
;; contains-milk?: list-of-string -> boolean ;; determines whether the list contains milk (define (contains-milk? alos) (cond [(empty? alos) false] [(cons? alos) (or (string=? "milk" (first alos)) (contains-milk? (rest alos)))]))And here's the solution to count-short-strings:
;; count-short-strings: list-of-string -> number ;; counts the number of strings in the list with 5 or fewer characters (define (count-short-strings alos) (cond [(empty? alos) 0] [(cons? alos) (cond [(<= (string-length (first alos)) 5) (+ 1 (count-short-strings (rest alos)))] [else (count-short-strings (rest alos))])]))