Due at the beginning of lecture on Wednesday, April 7, 1999
All of these problems should be done without using side effects (i.e. redefining variables or using set!). Be sure to test your functions on various cases, including empty lists, simple lists with no sublists, complex lists, etc.
(define y '(2 3))
(define z (cons 3 y))
(define w (cons z y))
(define x (cons w '(2 3)))
(define x '(1 2 3))
(define y (append x x))
(define z (cons x x))
(define foo '(7 2 3))
show the value of each of the following expressions. If something is wrong, say so. (Obviously you could trivialize the problem by typing these expressions into a Scheme interpreter and transcribing the results. Feel free to use a computer to check your answers, but be sure you can answer the questions without using a machine.)
(car x)
(cdar x)
(cdar z)
(cons x foo)
(equal? (cdr x) (cdr foo))
(equal? (cdr y) x)
(equal? (cdr z) (car z))
(eqv? (cdr z) (car z))
(eqv? (cdr x) (cdr foo))
(car '(cadar x))
(list-max '(1 2 3 4)) => 4
(list-max '(1 17 192 -76)) => 192
(divisors 6) => (1 2 3)
(divisors 28) => (1 2 4 7 14)
(is-perfect? 6) => #t
(is-perfect? 28) => #t
(is-perfect? 24) => #f
(fringe '(not very interesting)) => (not very interesting)
(fringe '((this is) a (seriously ((more ( ) (complex)) tree)))) =>
(this is a seriously more complex tree)
(rev '(1 2 3 4)) => (4 3 2 1)
(rev '((A B) C (D (E F))) => ((D (E F)) C (A B))
(deep-rev '(1 2 3 4)) => (4 3 2 1)
(deep-rev '((A B) C (D (E F))) => (((F E) D) C (B A))