Lecture #1: In Class Activity
Solution Key
Problem 1
- ;; Error: Unbound variable 1
- (1 2 3)
- (HELLO WORLD)
- ;; Error: Unbound function 'Hello
- WUMPUS
- ;; Error: Unbound variable Wumpus
Problem 2
(+ 31 (* 3 2) (/ 8 2) 9)
(+ 31 6 (/ 8 2) 9)
(+ 31 6 4 9)
50
Problem 3
- A
- B
- B
- A
Problem 4
Evaluation begins as (if attempts to formulate it's arguments by evaluating
the (or) statement. (listp 1) evaluates to nil, (listp 2) evaluates to nil,
(null nil) evaluates to t. Evaluation stops there; (not nil) is never
evaluated. Since the (or) expression returned true, the next argument to
(if) (the then clause) is evaluted: (listp '(1 2 3)) returns t. The entire
code expression therefore returns t.
Problem 5
> (defun hypo (x y)
(sqrt (+ (* x x)
(* y y)
)
)
)
HYPO
> (hypo 3 4)
5.0
Back to main page...