Skip to content

Commit

Permalink
Merge remote-tracking branch 'ambrosebs/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
swannodette committed Aug 19, 2011
2 parents 53d9958 + f03e5b8 commit 2efa2f5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
21 changes: 13 additions & 8 deletions src/match/core.clj
Expand Up @@ -970,16 +970,21 @@
`(defn ~name ~vars
~clj-form)))

(defmacro match [vars & clauses]
(defmacro match-1 [vars & clauses]
(binding [*line* (-> &form meta :line)
*warned* (atom false)]
(let [[vars clauses] (if (not (vector? vars))
[[vars] (mapcat (fn [[row action]]
(if (not= row :else)
[[row] action]
[row action]))
(partition 2 clauses))]
[vars clauses])]
(let [[vars clauses] [[vars] (mapcat (fn [[row action]]
(if (not= row :else)
[[row] action]
[row action]))
(partition 2 clauses))]]
`~(-> (emit-matrix vars clauses)
compile
n-to-clj))))

(defmacro match [vars & clauses]
(binding [*line* (-> &form meta :line)
*warned* (atom false)]
`~(-> (emit-matrix vars clauses)
compile
n-to-clj)))
6 changes: 3 additions & 3 deletions test/match/test/core.clj
Expand Up @@ -216,16 +216,16 @@

(deftest match-single-1
(is (= (let [x 3]
(match x
(match-1 x
1 :a0
2 :a1
:else :a2))
:a2)))

(deftest match-single-2
(is (= (let [x 3]
(match (mod x 2)
(match-1 (mod x 2)
1 :a0
2 :a1
:else :a2))
:a0)))
:a0)))

0 comments on commit 2efa2f5

Please sign in to comment.