MASSACHVSETTS INSTITVTE OF TECHNOLOGY Depart ment of Electrical Engineering and Computer Science 01-Structure and Interpret at ion of Computer Programs Spring Semester, 2005 Quiz it NAME: Sample Solutions Part 1:(25 points) Question 1 (define (rotate-left cycle) (cdr cycle)) Question 2: (define (rotate-right cycle) (define (aux where start (if (eq? (cdr where)start) where Caux (cdr where) start))) (aux cycle cycle)) Question 3: (define (insert-cycle! new cycle) et ((new-cell (list new )) (set-cdr! new-cell cycle) (set-cdr! (rotate-right cycle) new-cell) 'done)) Question 4 (define (delete-cycle! cycle) (set-cdr! (rotate-right cycle)(rotate-left cycle) set-cdr! cycle’( done) Part 2: (30 points
!""# $% %& '""( )
6.001, Spring Semester, 2005--Quiz II Enclosing eny ironment E1 E2 E2 GE E3 GE E4 E1 Question 6: Environment Value to which bound etI -start GE Pl set!-careful I GE E2 5 GE E4 (10) act ion new E P4 current E 10 Question 7 location:卫2 value (5) Part 3(15 points) Question 8:A Question 9: K Question 10: H Question 1l: G Question 12: J Part 4 30 points
' % * ' + , - * .// - %01% %01 * ' . , , * + * + ) *) ! " # $
6.001, Spring Semester, 2005--Quiz Il Ques Question 14. SHeETs (lambda o (fold-right +0 map (lambda (thing)(ask thing ' SHEETS)) Question 1 110 Question 17 Question 18. Question 19 (define (aged-cabinet self name) (let ((cabinet-part(cabinet self name Cage 0)) (make-handler ADD-THING (lambda (thing) (if (< age 4) (ask cabinet-part 'ADdThING thing (set! age ( age 1))) 'broken))) cabinet -part))) Question 20: (define (located-cabinet self name x y) (let((cabinet -part (cabinet self name)) (located-object-part (located-object self x y))) (make-handler (make-methods cabinet -part located-ob ject -part)))
+ % % &' % % % % ! !" # $ % & ' ( ( & ' (
(ceefinrcta-nIc ly)loi gehu x wts ga Question 21 Sanpl em Sewo Ser 4)any ( My ann(rn3: n4 c: n3lee CQp Sn40 anc(eesnl jec(s)nR CAe(sx! 3ewoc Question 22 No QuzIsXsY! Sanpl emS3ewx 3ewyo Sn40 4eat CAe(sx! 3ewxo Sn0 4eat CAe(sy! 3ewyoo
, ) ' **+' , ( &$ ) () -.$ )& )' &$ )& '$ )'