;;;; This example illustrates the use of the design recipe for ;;;; functions consuming compound (structured) data. ;; (Step 1) Structure and data definition (define-struct student (name id age major)) ;; A Student is (make-student String Number Number Symbol) ;; (Step 1 continued) Student examples (define bill (make-student "Bill" 1234 20 'math)) (define alice (make-student "Alice" 9999 25 'comp-sci)) ;; (Step 2) Contract/purpose/header ;; minor? : Student -> Boolean ;; determines whether a student is under 21 years old ;; (define (minor? a-student) ...) #| (Step 4) Template (define (minor? a-student) ... (student-name a-student) ... ... (student-id a-student) ... ... (student-age a-student) ... ... (student-major a-student) ... ) |# ;; (Step 5) Body (define (minor? a-student) (< (student-age a-student) 21)) ;; (Step 3) Examples and (Step 6) Tests (boolean=? (minor? bill) true) (boolean=? (minor? alice) false)