Created
January 22, 2020 13:10
-
-
Save freakhill/0d64e2b95c3dcb4405f02b2c57d0ce44 to your computer and use it in GitHub Desktop.
because i was curious, also keywords not supporting spaces is puzzling, why?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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