CPSC 110 Lecture Notes - Lecture 16: Empty String, Doberman Pinscher, Border Collie
CPSC 110 verified notes
16/26View all
Document Summary
;; problem 1: refactor this function to use built in abstract functions. (@htdf keep-positive) (@signature (listof integer) -> (listof integer)) ;; produce list that only includes positive number from loi (check-expect (keep-positive empty) empty) (check-expect (keep-positive (list 2 3 -8 9 -11 -14)) (list 2 3 9)) (@template (listof integer)) (define (keep-positive loi) (cond [(empty? loi) empty] [else (if (positive? (first loi)) (cons (first loi) (keep-positive (rest loi))) (keep-positive (rest loi)))])) (@template use-abstract-fn) (define (keep-positive loi) (filter positive? loi)) ;; problem 2: complete the design of this function that produce list that only. ;; includes the values that are less than 10 using built-in abstract functions. (@htdf less-than-10-only) (@signature (listof integer) -> (listof integer)) ;; produce list that only includes the values that are less than 10 (check-expect (less-than-10-only empty) empty) (check-expect (less-than-10-only (list -2 3 8 9 11 14)) (list -2 3 8 9))