Skip to content
Browse files

* src/main/clojure/clojure/core/match.clj: MATCH-37: remove match-1

  • Loading branch information...
1 parent 9599b24 commit 5edc28c6cd5315818ec2a852e931f5b7fe7dff35 @swannodette swannodette committed Oct 28, 2011
Showing with 14 additions and 29 deletions.
  1. +10 −25 src/main/clojure/clojure/core/match.clj
  2. +4 −4 src/test/clojure/clojure/core/match/test/core.clj
View
35 src/main/clojure/clojure/core/match.clj
@@ -1572,27 +1572,6 @@
;; ============================================================================
;; # Match macros
-(defmacro match-1
- "Pattern match a single value. Clause question-answer syntax is like
- `cond`.
-
- Example:
- (let [x 1]
- (match-1 x
- 1 :answer1
- 2 :answer2
- :else :default-answer)))"
- [vars & clauses]
- (binding [*line* (-> &form meta :line)
- *locals* (dissoc &env '_)
- *warned* (atom false)]
- (let [[vars clauses] [[vars] (mapcat (fn [[row action]]
- (if (not= row :else)
- [[row] action]
- [row action]))
- (partition 2 clauses))]]
- `~(clj-form vars clauses))))
-
(defmacro match
"Pattern match a row of occurrences. Take a vector of occurrences, vars.
Clause question-answer syntax is like `cond`. Questions must be
@@ -1606,10 +1585,16 @@
[1 2 3] :answer1
:else :default-answer))"
[vars & clauses]
- (binding [*line* (-> &form meta :line)
- *locals* (dissoc &env '_)
- *warned* (atom false)]
- `~(clj-form vars clauses)))
+ (let [[vars clauses] (if (vector? vars)
+ [vars clauses]
+ [(vector vars)
+ (mapcat (fn [[c a]]
+ [(if (not= c :else) (vector c) c) a])
+ (partition 2 clauses))])]
+ (binding [*line* (-> &form meta :line)
+ *locals* (dissoc &env '_)
+ *warned* (atom false)]
+ `~(clj-form vars clauses))))
(defmacro matchv [type vars & clauses]
(binding [*vector-type* type
View
8 src/test/clojure/clojure/core/match/test/core.clj
@@ -278,15 +278,15 @@
(deftest match-single-1
(is (= (let [x 3]
- (match-1 x
+ (match x
1 :a0
2 :a1
:else :a2))
:a2)))
(deftest match-single-2
(is (= (let [x 3]
- (match-1 (mod x 2)
+ (match (mod x 2)
1 :a0
2 :a1
:else :a2))
@@ -296,7 +296,7 @@
;; whatever pattern they actually contain - David
(comment
(deftest match-single-3
- (is (= (match-1 [1 2]
+ (is (= (match [1 2]
[2 1] :a0
(_ :when #(= (count %) 2)) :a1
:else :a2)
@@ -478,7 +478,7 @@
(deftest exception-1
(is (= (try
- (match-1 :a :a (throw (Exception.)) :else :c)
+ (match :a :a (throw (Exception.)) :else :c)
(catch Exception e
:d))
:d)))

0 comments on commit 5edc28c

Please sign in to comment.
Something went wrong with that request. Please try again.