;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname lect03b) (read-case-sensitive #t) (teachpacks ((lib "universe.ss" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "universe.ss" "teachpack" "2htdp"))))) ; A book is: ; (make-book [string] [string] [number] [boolean]) ; (define-struct book (title author pages copyR?)) ; Examples of the data: (make-book "The Soul of Wit" "Shorty" 0 false) (define b1 (make-book "The Cat in the Hat" "Seuss" 31 true)) ; Note that 'define-struct' automagically creates ; functions for us: ; Constructor: ; make-book: string, string, number, boolean -> book ; Selectors: ; book-title : book -> string ; book-author : book -> string ; book-pages : book -> number ; book-copyR? : book -> boolean ; Predicate: ; book? : ANY -> boolean ; read-time: book -> number ; How long does it take to read `a-book`, in hours? ; #;(define (read-time a-book) -99) (check-expect (read-time (make-book "The Soul of Wit" "Shorty" 0 false)) 0) (check-expect (read-time b1) (+ 1 2/60)) ;;; AFTER making the test cases, we go back and write the code: ; read-time: book -> number ; How long does it take to read the book, in hours? ; (define (read-time a-book) (* (book-pages a-book) 2 1/60))