<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,4 +1,11 @@
 ; Write a Scheme expression whose evaluation would result in an error
-; if and were a procedure but actually will have a value because and
-; is a special form. Do the same for or.
+; if `and` were a procedure but actually will have a value because and
+; is a special form. Do the same for `or`.
 
+(defn and- [a b] (and a b))
+(defn or- [a b] (or a b))
+
+(defn loopy [] (loopy))
+
+(and false (loopy))
+(or true (loopy))</diff>
      <filename>1.1.6/m1.3.clj</filename>
    </modified>
    <modified>
      <diff>@@ -2,3 +2,13 @@
 ; returns 1 if the number is positive, -1 if the number is negative,
 ; and 0 if the number is 0.
 
+(defn sign [val]
+  (cond (&gt; val 0) 1
+        (&lt; val 0) -1
+        :else 0))
+
+(= 1 (sign 10))
+(= 1 (sign 1))
+(= 0 (sign 0))
+(= -1 (sign -1))
+(= -1 (sign -10))</diff>
      <filename>1.1.6/m1.4.clj</filename>
    </modified>
    <modified>
      <diff>@@ -10,3 +10,8 @@
 ; Write two definitions of true-false - one that uses if and one that
 ; uses cond.
 
+(defn true-false [val]
+  (if val 1 0))
+
+(= 1 (true-false (&gt; 3 2)))
+(= 0 (true-false (and (&gt; 3 2) (&lt; 3 1))))</diff>
      <filename>1.1.6/m1.5.clj</filename>
    </modified>
    <modified>
      <diff>@@ -9,15 +9,18 @@
 ; Design a square-root procedure that uses this kind of end test. Does this
 ; work better for small and large numbers?
 
-(defn abs [x]
-  (cond (&lt; x 0) (- x)
-        :else x))
+; Clojure builtin
+;(defn abs [x]
+;  (cond (&lt; x 0) (- x)
+;        :else x))
 
-(defn square [x]
-  (* x x))
+; Clojure builtin
+;(defn square [x]
+;  (* x x))
 
-(defn average [x y]
-  (/ (+ x y) 2))
+; Clojure builtin
+;(defn average [x y]
+;  (/ (+ x y) 2))
 
 (defn improve [guess x]
   (average guess (/ x guess)))</diff>
      <filename>1.1.7/1.7.clj</filename>
    </modified>
    <modified>
      <diff>@@ -3,9 +3,58 @@
 ; greater than or equal to 0, the roots are both real; otherwise the
 ; roots are complex with real part -b/2a. Define a procedure 
 ; smallest-real-part that takes the coefficients a, b and c as arguments
-; and returns either the real part of the roots (if theyare complex),
+; and returns either the real part of the roots (if they are complex),
 ; or else the real root having the smaller absolute value. Be sure
 ; that your procedure continues to work if some of the coefficients 
 ; or the discriminant are zero (but you may assume that a is always
 ; nonzero).
 
+(defn improve [guess x]
+  (average guess (/ x guess)))
+(defn good-enough? [guess x]
+  (or (= guess x)
+      (&lt; (abs (- (square guess) x)) (* x 0.0000001))))
+(defn sqrt-iter [guess x]
+  (if (good-enough? guess x)
+      guess
+      (recur (improve guess x)
+             x)))
+(defn sqrt [x]
+  (sqrt-iter 1.0 x))
+
+
+(defn discriminant [a b c]
+  (- (* b b) (* 4 a c)))
+
+(defn real-root? [a b c]
+  (&lt;= 0 (discriminant a b c)))
+
+(= true (real-root 1 0 0))
+(= true (real-root 1 0 -1))
+(= false (real-root 1 0 1))
+
+(defn real-part [a b c]
+  (/ (- b) (* 2 a)))
+
+(defn root [sign a b c]
+  ; -b +- sqrt(bb - 4ac)
+  ; --------------------
+  ;         2a
+  (/ (sign (- b) 
+           (sqrt (discriminant a b c)))
+     (* 2 a)))
+
+(defn root-one [a b c]
+  (root + a b c))
+(defn root-two [a b c]
+  (root - a b c))
+
+(defn smallest-real-part [a b c]
+  (if (real-root? a b c)
+      (min (abs (root-one a b c)) (abs (root-two a b c)))
+      (real-part a b c)))
+
+; todo: some concrete examples with known answers to test with?
+(smallest-real-part 1 0 0)
+(smallest-real-part 1 0 -1)
+(smallest-real-part 1 3 1)</diff>
      <filename>1.1.7/m1.6.clj</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>f33227bc70149ef041473d44a2441f0614741827</id>
    </parent>
  </parents>
  <author>
    <name>Jamie Macey</name>
    <email>jamie.git@tracefunc.com</email>
  </author>
  <url>http://github.com/jamie/sicp/commit/d0074a212f3074cc2c6c1595fb0149fab6fc65a7</url>
  <id>d0074a212f3074cc2c6c1595fb0149fab6fc65a7</id>
  <committed-date>2009-01-22T11:11:14-08:00</committed-date>
  <authored-date>2009-01-22T11:11:14-08:00</authored-date>
  <message>implement remaining sec 1.1 instructors exercises</message>
  <tree>b16eb42b2de6c0f1e47de0a0a220b4353ef57a58</tree>
  <committer>
    <name>Jamie Macey</name>
    <email>jamie.git@tracefunc.com</email>
  </committer>
</commit>
