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 18.1.15) (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 (define-struct ir (name price))
5 12687dd9 2023-08-04 jrmu
6 12687dd9 2023-08-04 jrmu ;An inventory-record (ir) is a structure
7 12687dd9 2023-08-04 jrmu ;(make-ir n p)
8 12687dd9 2023-08-04 jrmu ;where n is a symbol and p is a number.
9 12687dd9 2023-08-04 jrmu
10 12687dd9 2023-08-04 jrmu ;An inventory is either
11 12687dd9 2023-08-04 jrmu ;1. empty or
12 12687dd9 2023-08-04 jrmu ;2. (cons ir inv)
13 12687dd9 2023-08-04 jrmu ;where ir is an inventory record (ir) and inv is an inventory.
14 12687dd9 2023-08-04 jrmu
15 12687dd9 2023-08-04 jrmu ;; extract1 : inventory -> inventory
16 12687dd9 2023-08-04 jrmu ;; to create an inventory from an-inv for all
17 12687dd9 2023-08-04 jrmu ;; those items that cost less than $1
18 12687dd9 2023-08-04 jrmu (define (extract1 an-inv)
19 12687dd9 2023-08-04 jrmu (cond
20 12687dd9 2023-08-04 jrmu [(empty? an-inv) empty]
21 12687dd9 2023-08-04 jrmu [else
22 12687dd9 2023-08-04 jrmu (local ((define fi (first an-inv))
23 12687dd9 2023-08-04 jrmu (define ex (extract1 (rest an-inv))))
24 12687dd9 2023-08-04 jrmu (cond
25 12687dd9 2023-08-04 jrmu [(<= (ir-price fi) 1.00)
26 12687dd9 2023-08-04 jrmu (cons fi ex)]
27 12687dd9 2023-08-04 jrmu [else ex]))]))
28 12687dd9 2023-08-04 jrmu
29 12687dd9 2023-08-04 jrmu (define INV (list (make-ir 'JumpingJacks 0.75)
30 12687dd9 2023-08-04 jrmu (make-ir 'LaserPen 0.99)
31 12687dd9 2023-08-04 jrmu (make-ir 'BowlingPin 1.25)
32 12687dd9 2023-08-04 jrmu (make-ir 'NightLite 0.45)
33 12687dd9 2023-08-04 jrmu (make-ir 'Telescope 5.50)
34 12687dd9 2023-08-04 jrmu (make-ir 'Pogs 0.50)))