Permalink
Browse files

Add cond.

  • Loading branch information...
Arlen Christian Mart Cuss
Arlen Christian Mart Cuss committed Dec 12, 2012
1 parent 2c78086 commit 7f5e675f398b27a242edf7769ab749f05c1ff3e2
Showing with 30 additions and 0 deletions.
  1. +4 −0 lib/boot.rg
  2. +26 −0 spec/core_spec.rg
View
@@ -372,6 +372,10 @@
"Returns an array of (seq coll)."
(.to_a (seq coll)))
+(defmacro cond
+ ([])
+ ([test result & rest]
+ `(if ~test ~result (cond ~@rest))))
(ns ^{:doc "Implemenations of functions from clojure.string."}
rouge.string
View
@@ -125,4 +125,30 @@
[hd & tl] (map #(do (swap! q inc) (inc %)) [1 2 3])]
@q)))))
+(testing "cond"
+ (is (= 1 (cond
+ :else 1)))
+ (is (= 1 (cond
+ false 2
+ nil 3
+ true 1)))
+ (is (nil? (cond)))
+ (is (nil? (cond
+ false 1
+ nil 2)))
+ (is (= 1 (let [q (atom 0)]
+ (is (= :ok (cond
+ (swap! q inc) :ok
+ (swap! q inc) :bad
+ (swap! q inc) :very_bad)))
+ @q)))
+ (is (= 2 (let [q (atom 0)]
+ (is (= :ok (cond
+ (do
+ (swap! q inc)
+ nil) :bad
+ (swap! q inc) :ok
+ (swap! q inc) :very_bad)))
+ @q))))
+
; vim: set ft=clojure:

0 comments on commit 7f5e675

Please sign in to comment.