cs61a_sp08_mt1-05

# cs61a_sp08_mt1-05 - exercise 1.43 page 77 But in fact this...

This preview shows page 1. Sign up to view the full content.

Question 7 (7 points): This question is about the iterative-improve procedure from exercise 1.46, page 78: (define (iterative-improve good-enough? Improve) (define (help x) (if (good-enough? x) x (help (improve x)))) help) (a) Fill in the blanks in the following definition of piglatin: (define (piglatin wd) (word ((iterative-improve ______________________________________________________________________ _______________________________________________________________________ ) wd) ay)) (b) Another candidate for rewriting in terms of iterative-improve would be the repeated function from
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: exercise 1.43, page 77. But in fact this doesn’t work, because the “good enough” condition depends not on the current argument value, but on the number of times the function has been called. Write a function count-iterative-improve that’s like iterative-improve except that each of its two argument functions takes two arguments: the current guess, and the number of times the improve function has been called so far. Here’s how it will be used: (define (repeated fn num) (count-iterative-improve (lambda (x cnt) (= cnt num)) (lambda x cnt) (fn x))))...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern