(3pts)
For each of the following expressions, give its value (if any).
If the expression is illegal (i.e. drScheme gave an error message),
explain why (in about three words).
What you turn in should have both the expression and the resulting value.
For example: (* 3 2) = 6.
This problem can be entirely hand-written.
- (+ 22 10 -2)
- (- 20 (* 3 5) 2)
- (/ 44 14)
- (sqrt 16)
- (sqrt 16 25)
- (zero? (+ 2 -2))
- (and (= 3 3) (zero? 17))
- (and #t (or #f #t))
- (if (> 3 4) (/ 1 0) (/ 1 9))
- (if #f (if #f 3 4) (if #t 5 6))
- (+ #f #t)
- (if 3 4 5)
- (if #t 7)
- (define pi 3)
- (define area (lambda (r) (* pi r r)))
- (area 4)
- (lambda (x) (* 2 pi x))
If you don't understand why drScheme gives each of the answers
it does, be sure to talk it over with a friend or labby.
To think about only (not to be graded):
At Beginner level,
DrScheme gives an error when it sees two open-parentheses in a row,
since this is not something beginners want to do.
However, consider the following expression closely:
((lambda (x) (* 2 pi x)) 4)
.
Do you feel this should be an allowable expression?
If so, what should its value be?
In the future, when we raise the language level,
you can see what DrScheme thinks.
Hint:
Most physics book contain a formula relating acceleration to distance traveled.
You should use any applicable 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 two or three other values.
(What borderline cases are there?)