EXERCISE SET #1

1. Using Scheme as a desk calculator, determine the arithmetic mean of the numbers 74, 81, 87, and 90.

2. Give a Scheme expression of which the value is a four-element list with the number 7 as its first element, the symbol a the second, the number -12 the third, and the symbol ??? the fourth.

3. Give a Scheme expression of which the value is a three-element list with the symbol * as its first element and the number -5 as its second and third.

4. Give a Scheme expression that, when evaluated, determines whether the first element of the three-element list mentioned in the previous exercise is a symbol. (The result of the evaluation should be #t.)

5. Give a Scheme expression of which the value is a two-element list with the empty list as its first and second element.

6. After the definition

(define dozen 12)
what will be the value of the Scheme expression (number? dozen)?

7. Give a Scheme definition that will determine the sum of 31, 29, 31, 30, 31, and 10 and bind the identifier day-of-year to this sum.

8. Define a Scheme procedure square that, given any number as an argument, returns the square of that number.

9. Define a recursive Scheme procedure first-symbol that finds and returns the first element of a given list that is a symbol (but returns #f if none of the elements of the list is a symbol).

10. Define a recursive Scheme procedure add-1-to-each that, given any list of numbers, returns a list of equal length in which each element is 1 greater than the corresponding element of the given list. For example, the value of (add-1-to-each '(3 8 6)) should be (4 9 5).

11. Define a recursive Scheme procedure tally that counts and returns the number of occurrences of a given value in a given list. For example, the value of (tally 'a '(b a 7 c a a 3 a)) should be 4.

12. Define a Scheme procedure all-different? that determines whether all of the top-level elements of a given list are distinct (that is, not equal?).

I'll also be happy to discuss any of the exercises from chapters 1 and 2 of the text.


created June 9, 1996
last revised June 10, 1996

John David Stone (stone@math.grin.edu)