Permalink
Browse files

convert WildcardPattern to defrecord

  • Loading branch information...
1 parent 196016d commit 9c634e010dd118bc9f0a1a2db4ad1a25bb3ccc67 @swannodette swannodette committed May 6, 2013
Showing with 10 additions and 22 deletions.
  1. +10 −22 src/main/clojure/clojure/core/match.clj
@@ -321,7 +321,7 @@
(conj bindings [sym bind-expr])
bindings)
bindings (if (named-wildcard-pattern? p)
- (conj bindings [(sym p) bind-expr])
+ (conj bindings [(:sym p) bind-expr])
bindings)]
(PatternRow. (drop-nth ps n) action
bindings)))
@@ -556,7 +556,7 @@
;; Returns bindings usable by leaf-node
[f ocrs]
(let [ps (.ps ^PatternRow f)
- wc-syms (map #(sym %) ps)
+ wc-syms (map :sym ps)
wc-bindings (map vector wc-syms
(map leaf-bind-expr ocrs))]
(concat (bindings f)
@@ -844,27 +844,15 @@
;;
;; In practice, the DAG compilation eliminates any wildcard patterns.
-(defprotocol IWildcardPattern
- (sym [this]))
+(defrecord WildcardPattern [sym])
-(deftype WildcardPattern [sym _meta]
- IWildcardPattern
- (sym [_] sym)
- clojure.lang.IObj
- (meta [_] _meta)
- (withMeta [_ new-meta]
- (WildcardPattern. sym new-meta))
- Object
- (toString [_]
- (str sym)))
-
-(defn ^WildcardPattern wildcard-pattern
- ([] (WildcardPattern. '_ nil))
+(defn wildcard-pattern
+ ([] (WildcardPattern. '_))
([sym]
{:pre [(symbol? sym)]}
(if (= sym '_)
- (WildcardPattern. (gensym) nil)
- (WildcardPattern. sym nil))))
+ (WildcardPattern. (gensym))
+ (WildcardPattern. sym))))
(defn wildcard-pattern? [x]
(instance? WildcardPattern x))
@@ -874,10 +862,10 @@
(defn named-wildcard-pattern? [x]
(when (instance? WildcardPattern x)
- (not= (.sym ^WildcardPattern x) '_)))
+ (not= (:sym x) '_)))
-(defmethod print-method WildcardPattern [^WildcardPattern p ^Writer writer]
- (.write writer (str "<WildcardPattern: " (.sym p) ">")))
+(defmethod print-method WildcardPattern [p ^Writer writer]
+ (.write writer (str "<WildcardPattern: " (:sym p) ">")))
;; -----------------------------------------------------------------------------
;; ## Literal Pattern

0 comments on commit 9c634e0

Please sign in to comment.