Quiz 7 Answers, CS 257

Name: Barak A. Pearlmutter
CIRT user-id: barak
As an adolescent I aspired to lasting fame, I craved factual certainty, and I thirsted for a meaningful vision of human life - so I became a scientist. This is like becoming an archbishop so you can meet girls.
- Matt Cartmill

  1. Fill in the table (2 points each)
    what you type what Scheme prints
    `((+ 1 2) ,(+ 1 2) 4) ((+ 1 2) 3 4)
    (cons '(a b) '(c (d) e)) ((a b) c (d) e)
    (append '((a b) (c d)) '(e f)) ((a b) (c d) e f)
    (car ''a) quote
    (if 1 2 3) 2

  2. Define rev-noah, a function that takes two lists with an equal number of elements, packs them up two-by-two, and returns them in reverse order:
    (rev-noah '(a b c) (d e f))      ; ((c f) (b e) (a d))
    (rev-noah '() '())               ; ()
    Your definition should work (7 points) and be tail recursive (3 points).
    (define (rev-noah lis1 lis2)
      (aux lis1 lis2 '()))
    (define (aux lis1 lis2 res)
      (if (null? lis1)
          (aux (cdr lis1) (cdr lis2) `((,(car lis1) ,(car lis2)) ,@rev))))