week12 - CS 61A LAB EXERCISES = 3. Week 12 solutions Why...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 CS 61A Week 12 solutions LAB EXERCISES Err:510 3. Why doesn't make-procedure call eval? Because none of the arguments to lambda should be evaluated. In particular, the expressions that make up the body of the procedure are not evaluated until the procedure is *invoked*! 4.1, left-to-right (define (list-of-values exps env) (if (no-operands? exps) '() (let ((left (eval (first-operand exps) env))) (cons left (list-of-values (rest-operands exps) env))))) (define (list-of-values exps env) (if (no-operands? exps) '() (let ((right (list-of-values (rest-operands exps) env))) (cons (eval (first-operand exps) env) right)))) 4.2, Louis reordering (a) The trouble is that APPLICATION? cheats. The book has (define (application? exp) (pair? exp)) It really should be something like (define (application? exp) (and (pair? exp) (not (member (car exp) '(quote set! define if lambda begin cond))))) They get away with the shorter version precisely because EVAL doesn't call APPLICATION? until after it's checked for all the possible special forms. Louis (quite reasonably, I think) wants to rely on APPLICATION? behaving correctly no matter when it's called. (b) All we are changing is the syntax of an application, so we change the procedures that define the "application" abstract data type. These are on page 372 of the text. The new versions are: (define (application? exp) (tagged-list? exp 'call)) (define (operator exp) (cadr exp))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sheet1 Page 2 (define (operands exp) (cddr exp))
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This homework help was uploaded on 04/09/2008 for the course CS 61A taught by Professor Harvey during the Spring '08 term at University of California, Berkeley.

Page1 / 10

week12 - CS 61A LAB EXERCISES = 3. Week 12 solutions Why...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online