DOC PREVIEW
MIT 6 001 - Structure and Interpretation of Computer Programs

This preview shows page 1 out of 3 pages.

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

Unformatted text preview:

6.001, Spring 2004—Recitation 2 1MASSACHVSETTS INSTITVTE OF TECHNOLOGYDepartment of Electrical Engineering and Computer Science6.001—Structure and Interpretation of Computer ProgramsSpring 2004Recitation 2More SchemeScheme1. Special Forms(a) if - (if test consequent alternative)If the value of the test is not false (#f), evaluate the consequent, otherwise evaluate thealternative.(b) lambda - (lambda parameters body)Creates a procedure with the given parameters and body. Parameters is a list of namesof variables. Body is one or more scheme expressions. When the procedure is applied,the bo dy express ions are e valuated in order and the value of the last one is returned.Problems1. Evaluate the following expressions (assuming x is bound to 3):(if #t (+ 1 1) 17)(if #f #f 42)(if (> x 0) x (- x))(if 0 1 2)(if x 7 (7))6.001, Spring 2004—Recitation 2 22. Evaluate the following expressions:(lambda (x) x)((lambda (x) x) 17)((lambda (x y) x) 42 17)((lambda (x y) y) (/ 1 0) 3)((lambda (x y) (x y 3)) (lambda (a b) (+ a b)) 14)3. Suppose we’re designing an point-of-sale and order-tracking system for Wendy’s1. Luckilythe¨Uber-Qwuick drive through supports only 4 options: Classic Single Combo (hamburgerwith one patty), Classic Double With Cheese Comb o (2 patties), and Classic Triple withCheese Combo (3 patties), Avant-Garde Quadruple with Guacamole Combo (4 patties). Weshall encode these combos as 1, 2, 3, and 4 respectively. Each meal can be biggie-sized toacquire a larger box of fries and drink. A biggie-sized combo is represented by 5, 6, 7, and 8respectively.(a) Write a procedure named biggie-size which when given a regular combo returns abiggie-sized version.(b) Write a procedure named unbiggie-size which when given a biggie-sized combo returnsa non-biggie-sized version.(c) Write a procedure named biggie-size? which when given a combo, returns true if thecombo has been biggie-sized and false otherwise.(d) Write a procedure named combo-price which takes a combo and returns the price ofthe combo. Each patty costs $1.17, and a biggie-sized version costs $.50 extra overall.16.001 and MIT do not endorse and are not affiliated with Wendy’s in any way. They merely capitalize on thepleasant way “biggie-size” rolls off the tongue.6.001, Spring 2004—Recitation 2 3(e) An order is a collection of combos . We’l e ncode an order as each digit representing acombo. For example, the order 237 represents a Double, Triple, and biggie-sized Triple.Write a procedure named empty-order which takes no arguments and returns an emptyorder.(f) Write a procedure named add-to-order which takes an order and a combo and returns anew order which contains the contents of the old order and the new combo. For example,(add-to-order 1 2) -> 12.(g) Write a procedure named order-size which takes an order and returns the number ofcombos in the order. For example, (order-size 237) -> 3.(h) Write a procedure named order-cost which takes an order and returns the total costof all the combos. You may find quotient (integer division)


View Full Document

MIT 6 001 - Structure and Interpretation of Computer Programs

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 Structure and Interpretation of Computer Programs
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 Structure and Interpretation of Computer Programs 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 Structure and Interpretation of Computer Programs 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?