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 19.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 ;sort : (X X -> boolean) (listof X) -> (listof X)
5 ;Given a-lox and op, sort the SchemeData.
7 ;insert : (X X -> boolean) X (listof X) -> (listof X)
8 ;Given op, an-x and a-lox, insert an-x in the proper position in a-lox by using op.
9 (define (sort-lox op a-lox)
10 (local ((define (sort op a-lox)
11 (cond
12 [(empty? a-lox) empty]
13 [(cons? a-lox) (insert op
14 (first a-lox)
15 (sort op (rest a-lox)))]))
16 (define (insert op an-x a-lox)
17 (cond
18 [(empty? a-lox) (cons an-x empty)]
19 [(op an-x (first a-lox)) (cons an-x a-lox)]
20 [else (cons (first a-lox) (insert op an-x (rest a-lox)))])))
21 (sort op a-lox)))
23 (define-struct ir (name price))
25 ;An inventory record (ir) is a structure
26 ;(make-ir n p)
27 ;where n is a symbol and p is a number.
29 ;An inventory is a (listof ir).
31 ;<ir? : ir ir -> boolean
32 ;Given ir1 and ir2, returns true if the price of ir1 is less than that of ir2.
33 (define (<ir? ir1 ir2)
34 (< (ir-price ir1)
35 (ir-price ir2)))
37 ;>ir? : ir ir -> boolean
38 ;Given ir1 and ir2, returns true if the price of ir1 is less than that of ir2.
40 (define (>ir? ir1 ir2)
41 (> (ir-price ir1)
42 (ir-price ir2)))
46 (define ir-list (list (make-ir 'WaterGun 5.50)
47 (make-ir 'PencilCase 1.25)
48 (make-ir 'Eraser 0.75)
49 (make-ir 'CellPhone 25.50)
50 (make-ir 'Doll 8.75)
51 (make-ir 'Helmet 15.75)))