6.001 Recitation 12Structure and Interpretation of Computer Programs March 16, 2005Muuutaaation1. Binding mutation(set! name value) - Evaluates value and modifies the binding of name to point to said value.2. Pair mutation(set−car! pair value) - Evaluates pair and value and mutates the car of the pair to contain value.(set−cdr! pair value) - Like set−car!, but modifies the cdr.3. Dynamic binding and fluid-let(fluid−let ((name value) (name value) ...)) - Same syntax as l et. All of the bin dings must alreadyexist. First saves th e current values of the b indings, then mutates them to their new values,then evaluates the body, then returns the bindin gs to their original values.4. List mutationWrite the expression that will mutate a into each of th e following forms.( d e f i n e a ( l i s t 1 ( l i s t 2) 3 ) )(5 ( 2 ) 3)(1 5 3)(1 ( 2 ) )(1 ( 5 ) 3)(1 ( ) 3)5. Counting( d e f i n e count ( l i s t 0 ) )( d e f i n e ( c o u n ter )( s e t − c a r ! count (+ ( c ar count ) 1 ) )( c a r count ) )Evaluate the follow ing expressions.( c oun t e r )( c oun t e r )( c oun t e r )Why is count a list?Could this be done with set!?16.001 Structure and Interpretation of Computer Programs Muuutaaation6. Interesting listsWrite code to generate the following lists (pardon the ASCII art)a. +---+---+| . | . |+-|-+-|-+v v+---+---+| 1 | . |+---+-|-+v+---+---+| 2 | / |+---+---+b. +---+---+ +---+---+ +---+---+| 1 | ---->| . | ---->| 3 | ---++---+---+ +-|-+---+ +---+---+ |^ | ^ |+-----------+ +---------------+7. MemoryDefine a seen? procedure that behaves like the following.( s e e n? 1) => #f( s e e n? 2) => #f( s e e n? 1) => #t( s e e n? ’ foo ) => #f( s e e n? 2) => #t( s e e n? ’ foo ) => #t(define (seen? obj)8. Brainte aserWhat does the following evaluate to in MIT Scheme?( d e f i n e ( magic ) ’ ( 1 2 3) )( magic ) =>( s e t − c a r ! ( magic ) 5)( magic )
View Full Document