; This is the "dead end" program encountered in the "Difference Between ; Dates" case study. It includes a call to a function general-day-span ; whose definition is not provided. ; Return the number of days spanned by earlier-date and later-date. ; earlier-date and later-date both represent dates in 1994, with earlier-date ; being the earlier of the two. ; Note: general-day-span is not implemented. (define (day-span earlier-date later-date) (cond ((same-month? earlier-date later-date) (same-month-span earlier-date later-date) ) ((consecutive-months? earlier-date later-date) (consec-months-span earlier-date later-date) ) (else (general-day-span earlier-date later-date) ) ) ) ; Access functions for the components of a date. (define (month-name date) (car date)) (define (date-in-month date) (cadr date)) ; Return true if date1 and date2 are dates in the same month, and ; false otherwise. Date1 and date2 both represent dates in 1994. (define (same-month? date1 date2) (equal? (month-name date1) (month-name date2)) ) ; Return the number of the month with the given name. (define (month-number month) (cond ((equal? month 'january) 1) ((equal? month 'february) 2) ((equal? month 'march) 3) ((equal? month 'april) 4) ((equal? month 'may) 5) ((equal? month 'june) 6) ((equal? month 'july) 7) ((equal? month 'august) 8) ((equal? month 'september) 9) ((equal? month 'october) 10) ((equal? month 'november) 11) ((equal? month 'december) 12) ) ) ; Return true if date1 is in the month that immediately precedes the ; month date2 is in, and false otherwise. ; Date1 and date2 both represent dates in 1994. (define (consecutive-months? date1 date2) (= (month-number (month-name date2)) (+ 1 (month-number (month-name date1))) ) ) ; Return the difference in days between earlier-date and later-date, ; which both represent dates in the same month of 1994. (define (same-month-span earlier-date later-date) (+ 1 (- (date-in-month later-date) (date-in-month earlier-date)) ) ) ; Return the number of days in the month named month. (define (days-in-month month) (cond ((equal? month 'january) 31) ((equal? month 'february) 28) ((equal? month 'march) 31) ((equal? month 'april) 30) ((equal? month 'may) 31) ((equal? month 'june) 30) ((equal? month 'july) 31) ((equal? month 'august) 31) ((equal? month 'september) 30) ((equal? month 'october) 31) ((equal? month 'november) 30) ((equal? month 'december) 31) ) ) ; Return the number of days remaining in the month of the given date, ; including the current day. date represents a date in 1994. (define (days-remaining date) (+ 1 (- (days-in-month (month-name date)) (date-in-month date))) ) ; Return the difference in days between earlier-date and later-date, ; which represent dates in consecutive months of 1994. (define (consec-months-span earlier-date later-date) (+ (days-remaining earlier-date) (date-in-month later-date)))