Permalink
Browse files

MATCH-86: Cannot AOT OrPatterns

pseudo-pattern detection happened via multimethods. While I could not
determine why multimethods present a problem here - it was simpler to
change pseudo-pattern detection to checking for the presence of a marker
interface.
  • Loading branch information...
1 parent bda8f85 commit 23adaf466fd026f9d4a12443032037dfc006b901 @swannodette swannodette committed Apr 21, 2014
Showing with 12 additions and 18 deletions.
  1. +8 −17 src/main/clojure/clojure/core/match.clj
  2. +4 −1 src/main/clojure/clojure/core/match/protocols.clj
@@ -3,7 +3,7 @@
(:use [clojure.core.match.protocols])
(:require [clojure.set :as set])
(:import [java.io Writer]
- [clojure.core.match.protocols IExistentialPattern]))
+ [clojure.core.match.protocols IExistentialPattern IPseudoPattern]))
;; =============================================================================
;; # Introduction
@@ -566,7 +566,7 @@
(defn select [pm]
(swap pm (necessary-column pm)))
-(declare default-specialize-matrix pseudo-pattern?)
+(declare default-specialize-matrix)
(defn specialize
([matrix]
@@ -576,6 +576,9 @@
(specialize-matrix p matrix)
(default-specialize-matrix p matrix))))
+(defn pseudo-pattern? [x]
+ (instance? IPseudoPattern x))
+
(defn pseudo-patterns [matrix i]
(filter pseudo-pattern? (column matrix i)))
@@ -1389,6 +1392,8 @@ col with the first column and compile the result"
(map #(specialize-or-pattern-row % pat ps) rows))))
(deftype OrPattern [ps _meta]
+ IPseudoPattern
+
Object
(toString [this]
(str ps))
@@ -1425,21 +1430,6 @@ col with the first column and compile the result"
(defmethod print-method OrPattern [p ^Writer writer]
(.write writer (str "<OrPattern: " (:ps p) ">")))
-;; -----------------------------------------------------------------------------
-;; Pseudo-patterns
-;;
-;; Pseudo-patterns like OrPatterns are not real patterns. OrPatterns
-;; are much like a macro, they just expands into a simpler form. This
-;; expansion is dealt with specially in first-column-chosen-case.
-
-(defmulti pseudo-pattern? type)
-
-(defmethod pseudo-pattern? OrPattern
- [x] true)
-
-(defmethod pseudo-pattern? :default
- [x] false)
-
;; -----------------------------------------------------------------------------
;; ## Guard Patterns
;;
@@ -1998,3 +1988,4 @@ col with the first column and compile the result"
`(let ~bindings
(match [~@bindvars#]
~@body))))
+
@@ -31,5 +31,8 @@
(defprotocol IVectorPattern
(split [this n]))
-;; marker
+;; markers
+
(definterface IExistentialPattern)
+
+(definterface IPseudoPattern)

0 comments on commit 23adaf4

Please sign in to comment.