Commits

John Chandler committed b5867ea

Switched to use macros for getting mid, and finding the value of the list at mid.

  • Participants
  • Parent commits 9b3ef06

Comments (0)

Files changed (1)

 
 (ns code-kata)
 
+(defmacro mid []
+  (list 'quot '(+ lower upper) 2) )
+
+(defmacro get-mid []
+  (list 'get 'list '(mid)))
 
 (defn
   #^{:test (fn []
   [item list]
   (loop [ lower 0
 		  upper (- (count list) 1) ]
-	(let [ mid (quot (+ lower upper) 2) ]
-	  (if (> lower upper)
-		-1
-		(if (< (get list mid) item)
-		  (recur (+ mid 1) upper )
-		  (if (= (get list mid) item)
-			mid
-			(recur lower (- mid 1))))))))
+	(if (> lower upper)
+	  -1
+	  (if (< (get-mid) item)
+		(recur (+ (mid) 1) upper )
+		(if (= (get-mid) item)
+		  (mid)
+		  (recur lower (- (mid) 1)))))))
 
 (test #'chop)