Skip to content

Commit

Permalink
Change Implementation Of Predicate Normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkiel committed Sep 14, 2017
1 parent cd937ea commit 89883be
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/phrase/alpha.cljc
Expand Up @@ -8,10 +8,6 @@
[clojure.string :as str]
[clojure.walk :as walk]))

(defn regex? [x]
#?(:clj (instance? java.util.regex.Pattern x)
:cljs (regexp? x)))

(defn- normalize-pred
"Retains symbols in pred. Replaces things like numbers with symbols.
Expand All @@ -21,7 +17,7 @@
mappings (atom {})]
{::normalized-pred
(walk/postwalk
#(if (or (number? %) (string? %) (regex? %))
#(if-not (or (symbol? %) (sequential? %))
(let [sym (symbol (str "x" (swap! counter inc)))]
(swap! mappings assoc (keyword (name sym)) %)
sym)
Expand Down Expand Up @@ -126,7 +122,7 @@
mappings (atom (zipmap bindings (repeat nil)))]
{:pred
(walk/postwalk
#(if (or (some #{%} bindings) (= '_ %) (number? %) (string? %) (regex? %))
#(if (or (some #{%} bindings) (= '_ %) (not (or (symbol? %) (sequential? %))))
(let [sym (symbol (str "x" (swap! counter inc)))]
(when (some #{%} bindings)
(swap! mappings assoc % (keyword (name sym))))
Expand Down Expand Up @@ -179,3 +175,10 @@
"Removes the default phraser."
[]
(remove-method phrase* []))

(comment
(methods phrase*)
(remove-all-methods phrase*)
(sequential? [:a])
(sequential? (list :a))
)

0 comments on commit 89883be

Please sign in to comment.