DOC PREVIEW
MIT 6 001 - Recitation 16b

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:

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs Spring, 2007 Recitation 16b, April 18 Higher Order Procedures Practice (Mike Leventon) Dr. Kimberle Koile 1. Write a function swap that takes a function f, and returns a function that takes two arguments, and returns f with the variables swapped: (f x y) == ((swap f) y x) For example, ((swap -) 4 5) 1. 2. Composing functions Now try to write the function compose that takes two functions, f and g, and returns a function, that takes one argument, and composes f and g on that argument. Example: composing double and cube means take the double of the cube of x ((compose double cube) 3) => (double (cube 3)) => 54 3. Using compose, define the function f^3/2 which takes a number x and computes x 3/2 . 4. Repeated Composition of Functions We saw how to compose two functions to produce another function. For example, we can define the following: (define fourth-power (compose square square)) (define eight-power (compose square (compose square square))) ... and so on ...Write a recursive procedure called repeat that takes a function f and an integer n, and composes f, n times. For example: (define fourth-power (repeat square 2)) (define eight-power (repeat square 3)) ... and so on ... 5. Iterative Repeat: Write a version that creates the repeat procedure iteratively by calling compose. (Note: The procedure created will run as a recursive procedure.) 6. Iterative Repeated 2: Write a version of repeat that creates a procedure that will run as an iterative procedure. (Hint: Do not use


View Full Document

MIT 6 001 - Recitation 16b

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 Recitation 16b
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 Recitation 16b 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 Recitation 16b 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?