code cleanup

This commit is contained in:
Nathan Marz 2016-05-29 00:34:51 -04:00
parent f49f371eea
commit 637f7fc819
2 changed files with 37 additions and 38 deletions

View file

@ -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

View file

@ -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