Problem 1 (2 points)

Consider the procedure legal? below:

(define (legal? c)
  (and (number? c) (> c 0)) )

Write a procedure not-legal? that returns true when legal? returns false, and vice versa. Your not-legal? procedure should be a combination of uses of the following procedures: and, or, >= (greater than or equal to), <= (less than or equal to), and not-number? (which returns true when number? returns false, and vice versa); it should not use cond, if, or not.

Problem 2 (3 points)

Consider a procedure named double that, given a word as argument, returns a two-word sentence. The first word is two. The second word is the result of adding an "s" to the end of the argument. Some examples of how double should behave appear below.

expression

intended result

(double 'apple)

(two apples)

(double 'bus)

(two buss)

(double 'box)

(two boxs)

Now consider some incorrect implementations of double. For each one, indicate what the call

(double 'apple)

will return. If no value is returned because the procedure crashes, give the error message that results.

procedure

returned value or error message

(define (double wd)
  (sentence 'two '(word wd s)))

(define (double wd)
  (sentence 'two (sentence wd s)) )

(define (double wd)
  (sentence 'two (wd 's)) )

Problem 3 (2 points)

Fill in the blanks in the procedure below so that the code agrees with the comments.

; Given dates date1 and date2 in the form used in the Difference
; between Dates programs, return true when date1 is earlier in
; the year than date2, and return false otherwise.
; For example, (precedes-in-year? '(february 1) '(march 3)) should
; return true, while (precedes-in-year? '(february 1) '(january 17))
; and (precedes-in-year? '(february 1) '(february 1)) should return
; false.
(define (precedes-in-year? date1 date2)
  (<
    (day-span _____ _____ )
    (day-span _____ _____ ) ) )

Problem 4 (3 points)

Using only calls to month-name, date-in-month, month-number, and numeric comparison procedures, complete the alternative version of precedes-in-year? below. Your solution should use as few comparisons as possible.

; Given dates date1 and date2 in the form used in the Difference
; between Dates programs, return true when date1 is earlier in
; the year than date2, and return false otherwise.
(define (precedes-in-year? date1 date2)
  (cond