;; ------------------------------------------------------- (define-struct pair (name phone)) ;; A SNP (String-Number Pair) is (make-pair String Number) (define snp1 (make-pair "bob" 123)) (define snp2 (make-pair "alice" 456)) (define snp3 (make-pair "carol" 789)) ;; LOSN is one of: ;; -- empty ;; -- (cons SNP LOSN) (define losn1 empty) (define losn2 (cons snp1 empty)) (define losn3 (cons snp2 losn2)) (define losn4 (cons snp3 losn3)) ;; LOSN -> Number ;; find the number associated with Bob (check-expect (find losn2) 123) (check-expect (find losn3) 123) (check-expect (find losn4) 123) (check-error (find losn1) "not found") (define (find losn) (cond [(empty? losn) (error "not found")] [(cons? losn) (if (is-who? (first losn) "bob") (pair-phone (first losn)) (find (rest losn)))])) ;; SNP String -> Boolean ;; is the name field in the given SNP equal to name (check-expect (is-who? snp1 "bob") true) (define (is-who? snp name) (string=? (pair-name snp) name)) ;; ------------------------------------------------------- ;; HOMEWORK: ;; -------- ;; DESIGN THE FUNCTION collect, WHICH CONSUMES ;; A LIST OF String-Number Pairs AND RETURNS THOSE ;; WHOSE PHONE # IS BETWEEN 100 AND 600