cs61a_sp08_mt1-05

cs61a_sp08_mt1-05 - exercise 1.43, page 77. But in fact...

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

View Full Document Right Arrow Icon
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
Background image of page 1
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

This note was uploaded on 08/26/2009 for the course CS 61A taught by Professor Harvey during the Spring '08 term at Berkeley.

Ask a homework question - tutors are online