This preview shows page 1 out of 2 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 2 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

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

MIT 6 001 - Study Notes

Documents in this Course
Quiz 1

Quiz 1

6 pages

Databases

Databases

12 pages

rec20

rec20

2 pages

Quiz II

Quiz II

15 pages

Streams

Streams

5 pages

Load more
Download Study Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Study Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Study Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?