Skip to content

Instantly share code, notes, and snippets.

@wandersoncferreira
Last active October 16, 2020 16:46
Show Gist options
  • Save wandersoncferreira/aa808c9570fda8df6a08d5e94be3bae6 to your computer and use it in GitHub Desktop.
Save wandersoncferreira/aa808c9570fda8df6a08d5e94be3bae6 to your computer and use it in GitHub Desktop.
(defmacro demangle [sym]
(let [prefix# (str (gensym))
name# (symbol (str prefix# sym))
fn# `(defn ~name# [] (str (quote ~sym)))]
`(-> ~fn#
var-get
class
str
(clojure.string/split (re-pattern ~prefix#))
last
(clojure.string/split #"__\d")
first)))
(demangle !*&#-+=$%.><?|)
;; => "_BANG__STAR__AMPERSAND__SHARP___PLUS__EQ_$_PERCENT__DOT__GT__LT__QMARK__BAR_"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment