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 ;; extract1 : inventory -> inventory
11 12687dd9 2023-08-04 jrmu ;; to create an inventory from an-inv for all
12 12687dd9 2023-08-04 jrmu ;; those items that cost less than $1
13 12687dd9 2023-08-04 jrmu (define (extract1 an-inv)
14 12687dd9 2023-08-04 jrmu (cond
15 12687dd9 2023-08-04 jrmu [(empty? an-inv) empty]
16 12687dd9 2023-08-04 jrmu [else (cond
17 12687dd9 2023-08-04 jrmu [(<= (ir-price (first an-inv)) 1.00)
18 12687dd9 2023-08-04 jrmu (cons (first an-inv) (extract1 (rest an-inv)))]
19 12687dd9 2023-08-04 jrmu [else (extract1 (rest an-inv))])]))