Created
November 23, 2017 00:03
-
-
Save nforgerit/cd9450e4775042361e6f7821c52d33d0 to your computer and use it in GitHub Desktop.
Clojure: Dynamic fn symbol
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 uuid [] (str (java.util.UUID/randomUUID))) | |
;; => #'user/uuid | |
(defmacro rule [body] | |
(eval `(def ~(symbol (str "rule--" (uuid) "--1")) | |
(fn [] ~body)))) | |
;; => #'user/rule | |
(rule (println "hej")) | |
;; => #'user/rule--a43302b7-a7f3-4648-9a07-0d37554f4ac8--1 | |
(rule--a43302b7-a7f3-4648-9a07-0d37554f4ac8--1) | |
;; => hej |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment