Exercise 1.
Do the following reading:
Exercise 2.
When you teach a class, people will get distracted if you say "um" too many times.
Write a count-ums that counts the number of times "um" appears in a sentence:
> (count-ums
'(today um we are going to um talk about the combining um method))
3
Here are some special-case count-ums procedures for sentences of particular lengths:
(define (count-ums0 sent)
0)
(define (count-ums1 sent)
(if (equal? 'um (first sent))
1
0))
(define (count-ums2 sent)
(if (equal? 'um (first sent))
(+ 1 (count-ums1 (bf sent)))
(count-ums1 (bf sent))))
(define (count-ums3 sent)
(if (equal? 'um (first sent))
(+ 1 (count-ums2 (bf sent)))
(count-ums2 (bf sent))))
Exercise 3.
Write a procedure countdown that works like this:
> (countdown 10)
(10 9 8 7 6 5 4 3 2 1 blastoff!)
Exercise 4.
Do the following reading:
Exercise 5.
Write a procedure numbers that takes a sentence as its argument and returns another sentence containing only the numbers in the argument:
Exercise 6.
Write a new version of the describe-time procedure. Instead of returning a decimal number, it should behave like this:
> (describe-time 22222)
(6 HOURS 10 MINUTES 22 SECONDS)
> (describe-time 4967189641)
(1 CENTURIES 57 YEARS 20 WEEKS 6 DAYS 8 HOURS 54 MINUTES 1 SECONDS)
HINT: use quotient
!
Exercise 7.
Do the following reading:
Exercise 8.
As part of computing (factorial 6)
, Scheme computes (factorial 2)
and
gets the answer 2. After Scheme gets that answer, how does it know what to do next?
Exercise 9.
Do the following reading:
Exercise 10.
Here's an example of how the procedure remove-once should work:
> (remove-once 'morning '(good morning good morning))
(GOOD GOOD MORNING)
(It's okay if remove-once removes the other "morning" instead, as long as it removes only one of them.)
Exercise 11.
Write differences, which takes a sentence of numbers as its argument and returns a sentence containing the differences between adjacent elements. (The length of the returned sentence is one less than that of the argument.)
Exercise 12.
Write a procedure called location that takes two arguments, a word and a sentence. It should return a number indicating where in the sentence that word can be found. If the word isn't in the sentence, return #f. If the word appears more than once, return the location of the first appearance.