(require 2htdp/image) ;; Lecture: Monday, Feb 24th ;; [X Y -> Y] Y [Listof X] -> Y (define (process op base lox) (cond [(empty? lox) base] [(cons? lox) (op (first lox) (process op base (rest lox)))])) ;; all : [X -> Y] [Listof X] -> [Listof Y] (define (all op lox) (cond [(empty? lox) empty] [(cons? lox) (cons (op (first lox)) (all op (rest lox)))])) ;; all+1 : [Listof Number] -> [Listof Number] ;; add 1 to each number in lon (define (all+1 lon) (all add1 lon)) ; using all with X = Number, Y = Number (check-expect (all+1 '(1 2 3)) '(2 3 4)) (check-expect (all+1 '()) '()) ;; all-lengths : [Listof String] -> [Listof Number] ;; determine the length of each string in los (define (all-lengths los) (all string-length los)) ;; using all with X = String, Y = Number (check-expect (all-lengths (list "foo" "a" "bar")) '(3 1 3)) (check-expect (all-lengths '()) '()) ;; Notes: ;; process is built in: it is called foldr ;; all is built in: it is called map