Permalink
Browse files

MATCH-42 fix so that quoted symbols are treated as literals

  • Loading branch information...
1 parent 2192014 commit 6721be4fba74561038539e12667bc04cc5fc94cc @miner miner committed with swannodette Nov 30, 2011
Showing with 32 additions and 1 deletion.
  1. +1 −0 src/main/clojure/clojure/core/match.clj
  2. +31 −1 src/test/clojure/clojure/core/match/test/core.clj
@@ -1456,6 +1456,7 @@
(vector? pat) (recur (concat pats pat) seen dups)
(map? pat) (recur (concat pats (vals pat)) seen dups)
(seq? pat) (cond
+ (= (first pat) 'quote) (recur pats seen dups)
(= (first pat) :or) (let [wds (map wildcards-and-duplicates
(map list (take-nth 2 pat)))
mseen (apply set/union (map first wds))]
@@ -196,6 +196,36 @@
:else :fail))
:success)))
+(deftest same-symbol-using-guards
+ (is (= (let [e '(+ 1 (+ 2 3))
+ op (first e)
+ op? #(= % op)]
+ (match [e]
+ [([p :when op? x ([p2 :when op? y z] :seq)] :seq)] (list p x y z)))
+ '(+ 1 2 3))))
+
+(deftest quoted-symbol
+ (is (= (let [e '(+ 1 (+ 2 3))]
+ (match [e]
+ [(['+ x (['+ y z] :seq)] :seq)] (list '+ x y z)))
+ '(+ 1 2 3))))
+
+(deftest literal-quote
+ (is (= (let [e 'quote
+ f 10]
+ (match [e f]
+ ['quote quote] quote))
+ 10)))
+
+
+(deftest literal-quote-seq
+ (is (= (let [e '(:a (quote 10))]
+ (match [e]
+ [([quote (['quote 10] :seq)] :seq)] quote))
+ :a)))
+
+
+
(extend-type java.util.Date
IMatchLookup
(val-at* [this k not-found]
@@ -521,4 +551,4 @@
[([1 2] :seq) _] :a2
[_ 2] :a3
:else :a4))
- :a3)))
+ :a3)))

0 comments on commit 6721be4

Please sign in to comment.