]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex1_1.clj
Solution to 4.33. This had been difficult to get right, though conceptually it was
[sicp.git] / src / sicp / ex1_1.clj
1 (ns sicp.ex1_1
2   (:use [sicp utils]
3         [clojure.contrib trace test-is]))
4
5 ;; exercise 1.1: What is the result printed by the interpreter in response
6 ;;               to each expression (in order) ?
7
8 (def a 3)
9 (def b (+ a 1))
10
11 (+ a b (* a b))  ; 19
12 (= a b) ; false
13
14 (if (and (> b a) (< b (* a b)))
15     b
16     a)   ; 4
17
18 (cond (= a 4) 6
19       (= b 4) (+ 6 7 a)
20       :else 25)  ; 16
21
22 (+ 2 (if (> b a) b a)) ; 6
23
24 (* (cond (> a b) a
25          (< a b) b
26          :else -1)
27    (+ a 1))      ; 16