code cleanup
This commit is contained in:
parent
f49f371eea
commit
637f7fc819
2 changed files with 37 additions and 38 deletions
|
|
@ -17,41 +17,6 @@
|
||||||
(:import [com.rpl.specter Util])
|
(: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]
|
(defn spy [e]
|
||||||
(println "SPY:")
|
(println "SPY:")
|
||||||
(println (pr-str e))
|
(println (pr-str e))
|
||||||
|
|
@ -76,8 +41,42 @@
|
||||||
|
|
||||||
#+cljs
|
#+cljs
|
||||||
(defn throw-illegal [& args]
|
(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]
|
(defn benchmark [iters afn]
|
||||||
(time
|
(time
|
||||||
|
|
|
||||||
|
|
@ -444,7 +444,7 @@
|
||||||
;; - with invokedynamic here, could go directly to the code
|
;; - with invokedynamic here, could go directly to the code
|
||||||
;; to invoke and/or parameterize the precompiled path without
|
;; to invoke and/or parameterize the precompiled path without
|
||||||
;; a bunch of checks beforehand
|
;; 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
|
cache-sym (gensym "pathcache") ;; used for cljs
|
||||||
|
|
||||||
;; this is used to avoid warnings in cljs code about undeclared var
|
;; this is used to avoid warnings in cljs code about undeclared var
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue