Blob


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 |22.2|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp")))))
4 ;Exercise 22.2.1. Define an abstraction of the functions convertCF and names from section 21.1 using the new recipe for abstraction. Solution
6 (define-struct ir (name price))
8 ;An inventory record (ir) is a structure
9 ;(make-ir name price)
11 #|
13 ;; convertCF : lon -> lon
14 (define (convertCF alon)
15 (cond
16 [(empty? alon) empty]
17 [else
18 (cons (operator (first alon))
19 (convertCF (rest alon)))]))
21 ;; names : (listof ir) -> los
22 (define (names aloir)
23 (cond
24 [(empty? aloir) empty]
25 [else
26 (cons (operator (first aloir))
27 (names (rest aloir)))]))
29 |#
31 ;abs-func : (X -> Y) -> ((listof X) -> (listof Y))
32 (define (abs-map operator)
33 (local ((define (map alox)
34 (cond
35 [(empty? alox) empty]
36 [else (cons (operator (first alox))
37 (map (rest alox)))])))
38 map))
40 ;C->F : number -> number
41 (define (C->F temp)
42 (+ (* 9/5 temp) 32))
44 (define convertCF (abs-map C->F))
45 (define names (abs-map ir-name))
47 (define listofir (list (make-ir 'Pencil 0.40)
48 (make-ir 'Eraser 1.99)
49 (make-ir 'Pen 1.25)
50 (make-ir 'PaperClip 0.05)
51 (make-ir 'Highlighter 4.50)))