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.
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) |
|
(define (double wd) |
|
(define (double wd) |
|
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 _____ _____ ) ) )
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
For the following Scheme expressions, write the value that the STk would output if you were to type it in. If an expression produces an error, then just write ERROR.
(if (equal? 'that (or 'this 'that '(the other))) (se (word) (quote (to say))) (se (quote (+ 2 2)) 'always 'makes (se (word (word) 'a) '5)))
(define (mystery x) (or (and (zero? x) '(+ x 5)) (and (= x 3) 5) (se 'o (mystery (- x 2)))))Give the results of the following calls. If a call results in an error, write ERROR. If it results in an infinite recursion, write INFLOOP
Part A: How would you change the following accessors to accomodate this change?
(define (year date) (item 3 date)) (define (month-name date) (first date)) (define (day-of-month date) (item 2 date))Part B: Is it necessary to change anything else in the case study? Why or why not?