QUIZ 5, CS257, Spring 99 name:_Barak Pearlmutter______________ uid:___barak_______@unm.edu Careful attention to small detail often proves superior to genius. -- Cicero There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. -- C. A. R. Hoare A work is finished when we can no longer improve it, though we know it to be inadequate and incomplete. We are so overtaxed by it that we no longer have the power to add a single comma, however indispensable. What determines the degree to which a work is done is not a requirement of art or of truth, it is exhaustion and, even more, disgust. -- Cioran. For each of the following, (a) calculate what it will return, and (b) rewrite it using LIST, APPEND, CONS, etc insead of backquote, or vice-versa as appropriate. (Please keep the LET in the rewrite.) 1. (let ((a 1) (f car)) `(the ,(+ a 2) brown ,@(map f '((a b) (c d) (e f))) fox)) RETURNS: (the 3 brown a c e fox) REWRITTEN: (let ((a 1) (f car)) (cons 'the (cons (+ a 2) (cons 'brown (append (map f '((a b) (c d) (e f))) '(fox)))))) 2. (let ((n 5)) `(if (= ,n 0) 1 (f ,(- n 1)))) RETURNS: (if (= 5 0) 1 (f 4)) REWRITTEN: (let ((n 5)) (list 'if (list '= n 0) 1 (list 'f (- n 1)))) 3. (let ((v 'x) (e '((f x x))) (vals '((12)))) (cons (cons 'lambda (cons (list v) e)) vals)) RETURNS: ((lambda (x) (f x x)) (12)) REWRITTEN: (let ((v 'x) (e '((f x x))) (vals '((12)))) `((lambda (,v) ,@e) ,@vals))