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 18.1.11-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 (define-struct star (name instrument))
6 ;A star is a structure
7 ;(make-star name instrument)
8 ;where both name and instrument are symbols.
10 (define alos
11 (list (make-star 'Chris 'saxophone)
12 (make-star 'Robby 'trumpet)
13 (make-star 'Matt 'violin)
14 (make-star 'Wen 'guitar)
15 (make-star 'Matt 'radio)))
17 ;A list-of-stars is either
18 ;1. empty or
19 ;2. (cons s los)
20 ;where s is a star structure and los is a list-of-stars.
21 ;
22 ;last-occurrence : symbol list-of-star -> star/false
23 ;Given a-name and a-los, find the last occurrence of a star with a-name in the name field and return this star structure. Return false if there is no star with a-name.
25 (define (last-occurrence a-name a-los)
26 (cond
27 [(empty? a-los) false]
28 [else (local ((define r (last-occurrence a-name (rest a-los))))
29 (cond
30 [(star? r) r]
31 [(symbol=? a-name (star-name (first a-los))) (first a-los)]
32 [else false]))]))
34 (last-occurrence 'Matt
35 (list (make-star 'Matt 'violin)
36 (make-star 'Matt 'radio)))
38 ;; maxi : non-empty-lon -> number
39 ;; to determine the largest number on alon
40 (define (maxi alon)
41 (cond
42 [(empty? (rest alon)) (first alon)]
43 [else (cond
44 [(> (first alon) (maxi (rest alon))) (first alon)]
45 [else (maxi (rest alon))])]))
47 (list 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)