Skip to content

Instantly share code, notes, and snippets.

@mkremins
Created November 27, 2014 22:21
Show Gist options
  • Save mkremins/518637b1e54fd4188987 to your computer and use it in GitHub Desktop.
Save mkremins/518637b1e54fd4188987 to your computer and use it in GitHub Desktop.
Inspect cljs.core defs in CLJS
(def replacements
[["_PLUS_" \+] ["_STAR_" \*] ["_SLASH_" \/] ["_QMARK_" \?] ["_BANG_" \!]
["_LT_" \<] ["_GT_" \>] ["_EQ_" \=] ["_DOTDOT_" ".."] ["_" \-]])
(defn unmunge [s]
(reduce (fn [s [before after]]
(clojure.string/replace s before after))
s replacements))
(defn alphabetical? [c]
(.test #"[A-Za-z]" c))
(defn capital? [c]
(.test #"[A-Z]" c))
(defn lowercase? [c]
(.test #"[a-z]" c))
(defn dynamic? [sym]
(let [s (name sym)]
(and (not= s \*) (= (first s) \*) (= (last s) \*))))
(defn mutating? [sym]
(= (last (name sym)) \!))
(defn predicate? [sym]
(= (last (name sym)) \?))
(defn protocol-fn? [sym]
(let [s (name sym)]
(and (some alphabetical? s) (= (first s) \-))))
(defn protocol? [sym]
(let [s (name sym)]
(and (= (first s) \I) (capital? (second s)))))
(defn type? [sym]
(let [s (name sym)]
(and (capital? (first s)) (lowercase? (second s)))))
(defn classify [sym]
(reduce (fn [tags [tag pred]] (if (pred sym) (conj tags tag) tags)) #{}
{:dynamic dynamic? :mutating mutating? :predicate predicate?
:protocol-fn protocol-fn? :protocol protocol? :type type?}))
(def syms (map (comp symbol unmunge) (js/Object.keys js/cljs.core)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment