Blame


1 12687dd9 2023-08-04 jrmu ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 12687dd9 2023-08-04 jrmu ;; about the language level of this file in a form that our tools can easily process.
3 12687dd9 2023-08-04 jrmu #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 12687dd9 2023-08-04 jrmu map : (X -> Y) (listof X) -> (listof Y)
5 12687dd9 2023-08-04 jrmu Given f and alox, map each element of type X from alox to an element in type Y according to the function f to return a (listof Y).
6 12687dd9 2023-08-04 jrmu
7 12687dd9 2023-08-04 jrmu (define (map alox)
8 12687dd9 2023-08-04 jrmu (fold consf alox empty))
9 12687dd9 2023-08-04 jrmu
10 12687dd9 2023-08-04 jrmu consf : X (listof Y) -> (listof Y)
11 12687dd9 2023-08-04 jrmu Given f, an-x, and a-loy, map an-x to an element Y according to f and then append to the beginning of a-loy.
12 12687dd9 2023-08-04 jrmu (define (consf)
13 12687dd9 2023-08-04 jrmu (
14 12687dd9 2023-08-04 jrmu
15 12687dd9 2023-08-04 jrmu
16 12687dd9 2023-08-04 jrmu (define (fold op alox base)
17 12687dd9 2023-08-04 jrmu (cond
18 12687dd9 2023-08-04 jrmu [(empty? alox) base]
19 12687dd9 2023-08-04 jrmu [else (op (first alox) (fold op (rest alox) base))]))
20 12687dd9 2023-08-04 jrmu