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-beginner-reader.ss" "lang")((modname 10.2.2) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
4 ;Data Definition
5 ;An ir (inventory record) is a structure
6 ;(make-ir s n) where s is a symbol and n is a number.
8 (define-struct ir (name price))
10 ;Data definition
11 ;An inventory is either
12 ;1. an empty list or
13 ;2. (cons ir inv) where ir is an inventory record (structure)
14 ;and inv is an inventory.
16 ;Contract, Purpose, Header
17 ;contains-doll? : inventory -> boolean
18 ;Takes in an-inv (inventory) and searches to see if
19 ;it contains 'doll. Return true or false.
20 ;
21 ;Template
22 ;
23 ;(define (contains-doll? an-inv)
24 ; (cond
25 ; [() ...]
26 ; [() (first an-inv) (contains-doll? (rest an-inv))]))
28 (define (contains-doll? an-inv)
29 (cond
30 [(empty? an-inv) false]
31 [(symbol=? (ir-name (first an-inv)) 'doll) true]
32 [else (contains-doll? (rest an-inv))]))
34 (define list1 (cons (make-ir 'hat 55)
35 (cons (make-ir 'match 25)
36 (cons (make-ir 'tricycle 1840)
37 (cons (make-ir 'jumprope 400)
38 (cons (make-ir 'doll 150) empty))))))
40 ;Contract, Purpose, Header
41 ;contains? : inventory symbol -> boolean
42 ;Takes in an-inv (inventory) and searches to see if
43 ;it contains keyword. Return true or false.
45 (define (contains? an-inv keyword)
46 (cond
47 [(empty? an-inv) false]
48 [(symbol=? (ir-name (first an-inv)) keyword) true]
49 [else (contains? (rest an-inv) keyword)]))