Homework One
Finger Exercises

Comp 210

Due: At the beginning of class on 97.Jan.21 (Wed.)

These exercises are to be done with DrScheme.

  1. Give the value returned by Scheme after evaluating each expression in the following order.
    1. (+ 22 (* 4 7) -2)
    2. (- 4 3 2)
    3. (and #t (or #f #t))
    4. (if #f (if #f 3 4) (if #t 5 6))
    5. (define pi 3)
    6. (define area (lambda (r) (* pi r r)))
    7. (area pi)
    8. ;((lambda (x) (* 2 pi x)) 3)
      ; Ignore this question, or (if you want) show
      ; what the answer _will_ be when we raise the
      ; language level in the future.
    9. (lambda (x) (* 2 pi x))
    10. (if (= 3 2) (/ 1 0) (/ 1 2))
    11. (+ #f #t)
  2. Write Scheme versions of the following mathematical formulae, and test each on at least two inputs (one of which should be some sort of borderline case, e.g. 32 degrees fahrenheit).
    1. celc( f ) = (5/9)(f-32)
    2. dist( a, t ) = 1/2 a t²
    3. root1( a, b, c ) = [-b - sqrt(b²-4ac)]/2a
    4. my-abs( x ) = x, if x >= 0, or -x if x < 0.
  3. Houston drivers love to drive fast. Most drivers accelerate quickly from a standing stop to the de-facto speed limit of 80 miles per hour (mph) and maintain that constant speed. Write a Scheme function that takes as parameters the acceleration (in mph per second) of a car and an elapsed driving time in seconds and returns the distance traveled (in feet) by the car. I strongly suggest that you use several helper functions to aid in making your program more readable.
  4. Hint: Most physics book contain a formula relating acceleration to distance traveled. You may certainly use any function already written for a previous exercise. You may wish to double-check your solution against these inputs:

    (houston-driver-distance 6 5) = 110
    (houston-driver-distance 10 10) = 704

    Also test your function on one or two other values.