Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
because i was curious, also keywords not supporting spaces is puzzling, why?
(ns keyword-reader-macro.core
(:import [clojure.lang LispReader LispReader$StringReader]))
(defn field []
(.getDeclaredField LispReader "dispatchMacros"))
(defn dispatch-macros []
(.get (field) LispReader))
(defn dispatch-reader!
([key]
(nth (dispatch-macros) (int key)))
([key afn]
(.set (field) LispReader
(->> (assoc (into [] (dispatch-macros))
(int key) afn)
(into-array clojure.lang.IFn)))))
(defn keyword-reader [reader & params]
(LispReader/read1 reader)
(keyword (apply (LispReader$StringReader.) reader params)))
(defn set-keyword-reader! []
(dispatch-reader! \k keyword-reader))
(set-keyword-reader!)
#k"keyword with spaces~~ yaaay"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.