Permalink
Browse files

improved regroup-keywords

  • Loading branch information...
1 parent 318c145 commit 6d0f3fe33c4a85a12366d447e82cab59e299f94a @miner miner committed with swannodette Dec 12, 2011
Showing with 6 additions and 7 deletions.
  1. +6 −7 src/main/clojure/clojure/core/match.clj
View
13 src/main/clojure/clojure/core/match.clj
@@ -1410,19 +1410,18 @@
(keys (.getMethodTable ^clojure.lang.MultiFn emit-pattern-for-syntax))))))))
-(defn- pattern-keyword? [kw]
- (#{:when :as} kw))
-
-(let [void (gensym)]
+(let [void (Object.)
+ void? #(identical? void %)
+ infix-keyword? #(#{:when :as} %)]
;; void is a unique placeholder for nothing -- we can't use nil
;; because that's a legal symbol in a pattern row
(defn- regroup-keywords [pattern]
(cond (vector? pattern)
(first (reduce (fn [[result p q] r]
(cond
- (= void p) [result q r]
- (and (not= void r) (pattern-keyword? q))
- [(conj result (list (regroup-keywords p) q r)) void void]
+ (void? p) [result q r]
+ (and (not (void? r)) (infix-keyword? q))
+ [(conj result (list (regroup-keywords p) q r)) void void]
:else [(conj result (regroup-keywords p)) q r]))
[[] void void]
(conj pattern void void)))

0 comments on commit 6d0f3fe

Please sign in to comment.