Created
April 16, 2012 13:27
-
-
Save athos/2398796 to your computer and use it in GitHub Desktop.
an example of Clojure 1.4 reader literals
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
(defn defn-reader [body] | |
(let [name (symbol (name (first (keys (dissoc (meta body) :tag))))) | |
args (read-string (:tag (meta body)))] | |
`(defn ~name ~args ~(seq body)))) | |
(.bindRoot #'default-data-readers {'defn #'defn-reader}) | |
#defn ^:fact ^"[x]" | |
[ | |
if (= x 0) | |
1 | |
(* x (fact (dec x))) | |
] | |
(fact 10) ;=> 3628800 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment