It's supposed to work like this:
> (who '(sells out)) (pete sells out roger sells out john sells out keith sells out)answer:every的第一个参数是一个function,而这里describe返回的是一个list。因此,应该将这两个函数改为:- (define (who sent)
- (every (lambda (person)
- (se person sent))
- '(pete roger john keith)))
- (define (prepend-every wd sent)
- (every (lambda (wd2)
- (word wd wd2))
- sent))
- (define (sentence-version func)
- (lambda (sent)
- (every func sent)))
9.7 Write a procedure called letterwords that takes as its arguments a letter and a sentence. It returns a sentence containing only those words from the argument sentence that contain the argument letter:
> (letterwords 'o '(got to get you into my life)) (GOT TO YOU INTO)- (define (letterwords letter sent)
- (keep (lambda (wd)
- (member? letter wd))
- sent))
9.8 Suppose we're writing a program to play hangman. In this game one player has to guess a secret word chosen by the other player, one letter at a time. You're going to write just one small part of this program: a procedure that takes as arguments the secret word and the letters guessed so far, returning the word in which the guessing progress is displayed by including all the guessed letters along with underscores for the not-yet-guessed ones:
> (hang 'potsticker 'etaoi) _OT_TI__E_Hint: You'll find it helpful to use the following procedure that determines how to display a single letter:
(define (hang-letter letter guesses) (if (member? letter guesses) letter '_))answer:- (define (hang-letter letter guesses)
- (if (member? letter guesses)
- letter
- '_))
- (define (hang wd guesses)
- (accumulate word
- (every (lambda (letter)
- (hang-letter letter guesses))
- wd)))
- (define (appearances arg1 arg2)
- (count (keep (lambda (x)
- (equal? arg1 x))
- arg2)))
9.11 Write a procedure unabbrev that takes two sentences as arguments. It should return a sentence that's the same as the first sentence, except that any numbers in the original sentence should be replaced with words from the second sentence. A number 2 in the first sentence should be replaced with the second word of the second sentence, a 6 with the sixth word, and so on.
> (unabbrev '(john 1 wayne fred 4) '(bill hank kermit joey)) (JOHN BILL WAYNE FRED JOEY) > (unabbrev '(i 3 4 tell 2) '(do you want to know a secret?)) (I WANT TO TELL YOU)answer:- (define (unabbrev sent1 sent2)
- (every (lambda (x)
- (if (not (number? x))
- x
- ((lambda (y)
- (item y sent2))
- x)))
- sent1))
9.12 Write a procedure first-last whose argument will be a sentence. It should return a sentence containing only those words in the argument sentence whose first and last letters are the same:
> (first-last '(california ohio nebraska alabama alaska massachusetts)) (OHIO ALABAMA ALASKA)Answer:- (define (first-last sent)
- (keep (lambda (wd)
- (equal? (first wd)
- (last wd)))
- sent))