Browse files

* src/main/clojure/clojure/core/match.clj: MATCH-41: sorted-set-by is…

… broken, change to collapse. Any sort function will change alter the user defined order.
  • Loading branch information...
1 parent 6721be4 commit a790f7900da9152dcdf290ade34b8001c47869f1 @swannodette swannodette committed Nov 30, 2011
Showing with 22 additions and 7 deletions.
  1. +13 −7 src/main/clojure/clojure/core/match.clj
  2. +9 −0 src/test/clojure/clojure/core/match/test/core.clj
View
20 src/main/clojure/clojure/core/match.clj
@@ -63,7 +63,7 @@
*clojurescript* false)
(def ^{:dynamic true} *line*)
-(def ^{:dynamic true} *locals*)
+(def ^{:dynamic true} *locals* nil)
(def ^{:dynamic true} *warned*)
(def ^{:dynamic true} *vector-type* ::vector)
(def ^{:dynamic true} *match-breadcrumbs* [])
@@ -555,13 +555,19 @@
() ps)
reverse))
+ (collapse [ps]
+ (reduce (fn [a b]
+ (if (pattern-equals (first (rseq a)) b)
+ a
+ (conj a b)))
+ [] ps))
+
(column-constructors
- ;; Returns a sorted-set of constructors in column i of matrix this
+ ;; Returns a vector of relevant constructors in column i of matrix this
[this i]
- (let [ps (group-vector-patterns (column this i))]
- (->> ps
- (take-while (comp not wildcard-pattern?))
- (apply sorted-set-by (fn [a b] (pattern-compare a b))))))
+ (let [ps (group-vector-patterns (column this i))
+ ps (take-while (comp not wildcard-pattern?) ps)]
+ (collapse ps)))
(switch-clauses
;; Compile a decision trees for each constructor cs and returns a clause list
@@ -836,7 +842,7 @@
(toString [_]
(if (nil? l)
"nil"
- (str l))))
+ (pr-str l))))
(defn ^LiteralPattern literal-pattern [l]
(LiteralPattern. l nil))
View
9 src/test/clojure/clojure/core/match/test/core.clj
@@ -552,3 +552,12 @@
[_ 2] :a3
:else :a4))
:a3)))
+
+(deftest match-order-5
+ (is (= (match [["foo"]]
+ [["foo"]] :a0
+ [["foo" a]] :a1
+ [["baz"]] :a2
+ [["baz" a b]] :a3
+ :else :a4)
+ :a0)))

0 comments on commit a790f79

Please sign in to comment.