From 637f7fc819bf064509c598d212c8bd39f4b159b5 Mon Sep 17 00:00:00 2001 From: Nathan Marz Date: Sun, 29 May 2016 00:34:51 -0400 Subject: [PATCH] code cleanup --- src/clj/com/rpl/specter/impl.cljx | 73 +++++++++++++++--------------- src/clj/com/rpl/specter/macros.clj | 2 +- 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/clj/com/rpl/specter/impl.cljx b/src/clj/com/rpl/specter/impl.cljx index 0edd11f..1aaa806 100644 --- a/src/clj/com/rpl/specter/impl.cljx +++ b/src/clj/com/rpl/specter/impl.cljx @@ -17,41 +17,6 @@ (:import [com.rpl.specter Util]) ) -;; these macroexpand functions are for path macro in bootstrap cljs -;; environment -#+cljs -(defn macroexpand' - [form] - (binding [cljs/*eval-fn* cljs/js-eval] - (cljs/eval (cljs/empty-state) - `(macroexpand (quote ~form)) - identity))) - -#+cljs -(defn do-macroexpand-all - "Recursively performs all possible macroexpansions in form." - {:added "1.1"} - [form] - (walk/prewalk (fn [x] - (if (seq? x) - (macroexpand' x) - x)) form)) - -#+clj -(defn do-macroexpand-all [form] - (riddley/macroexpand-all form)) - -;;this is not a secure way to generate uuids – the `path` implementation -;;for cljs uses an alternative strategy -#+cljs -(defn gen-uuid-str [] - (apply str (repeatedly 50 #(rand-int 9))) - ) - -#+clj -(defn gen-uuid-str [] - (str (java.util.UUID/randomUUID))) - (defn spy [e] (println "SPY:") (println (pr-str e)) @@ -76,8 +41,42 @@ #+cljs (defn throw-illegal [& args] - (throw (js/Error. (apply str args))) - ) + (throw (js/Error. (apply str args)))) + + +;; these macroexpand functions are for path macro in bootstrap cljs +;; environment +#+cljs +(defn macroexpand' + [form] + (binding [cljs/*eval-fn* cljs/js-eval] + (cljs/eval (cljs/empty-state) + `(macroexpand (quote ~form)) + identity))) + +#+cljs +(defn do-macroexpand-all + "Recursively performs all possible macroexpansions in form." + {:added "1.1"} + [form] + (walk/prewalk (fn [x] + (if (seq? x) + (macroexpand' x) + x)) form)) + +#+clj +(defn do-macroexpand-all [form] + (riddley/macroexpand-all form)) + +;; so that macros.clj compiles appropriately when +;; run in cljs (this code isn't called in that case) +#+cljs +(defn gen-uuid-str [] + (throw-illegal "Cannot get UUID in Javascript")) + +#+clj +(defn gen-uuid-str [] + (str (java.util.UUID/randomUUID))) (defn benchmark [iters afn] (time diff --git a/src/clj/com/rpl/specter/macros.clj b/src/clj/com/rpl/specter/macros.clj index f335fa0..d09ef8d 100644 --- a/src/clj/com/rpl/specter/macros.clj +++ b/src/clj/com/rpl/specter/macros.clj @@ -444,7 +444,7 @@ ;; - with invokedynamic here, could go directly to the code ;; to invoke and/or parameterize the precompiled path without ;; a bunch of checks beforehand - cache-id (i/gen-uuid-str) ;; used for clj + cache-id (if (= platform :clj) (i/gen-uuid-str)) cache-sym (gensym "pathcache") ;; used for cljs ;; this is used to avoid warnings in cljs code about undeclared var