Skip to content

Instantly share code, notes, and snippets.

@freakhill
Created January 22, 2020 13:10
Show Gist options
  • Save freakhill/0d64e2b95c3dcb4405f02b2c57d0ce44 to your computer and use it in GitHub Desktop.
Save freakhill/0d64e2b95c3dcb4405f02b2c57d0ce44 to your computer and use it in GitHub Desktop.
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