1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #reader(lib "htdp-intermediate-reader.ss" "lang")((modname 21.1.2-2) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp")))))
4 ;fold : (X Y -> Y) (listof X) Y -> Y
5 ;Given op and alox, return the value of op applied cumulatively on every value in alox. The value base specifies a value that is the base from which fold operates upon.
7 (define (fold op alox base)
10 [else (op (first alox) (fold op (rest alox) base))]))
16 ;(rest alox) : (listof X)
18 ;map1 : (listof X) -> (listof Y)
19 ;Given alox, map1 each element of type X from alox to an element in type Y according to the function f to return a (listof Y).
22 (fold consf alox empty))
27 ;(consf (first alox) (fold consf (rest alox) empty))
28 ;(cons (f (first alox)) (fold f (rest alox) empty))
32 ;Given x, y, map1 x to an element Y and then append to the beginning of y.
45 [else (cons (f (first lon))
46 (map1 f (rest lon)))]))
50 (equal? (map1 '(1 3 2 5 1 4 0 2 6 8 6 9 2 3 4 5 1 8 2))
51 (list 6 8 7 10 6 9 5 7 11 13 11 14 7 8 9 10 6 13 7))