Skip to content

Instantly share code, notes, and snippets.

@nforgerit
Created November 23, 2017 00:03
Show Gist options
  • Save nforgerit/cd9450e4775042361e6f7821c52d33d0 to your computer and use it in GitHub Desktop.
Save nforgerit/cd9450e4775042361e6f7821c52d33d0 to your computer and use it in GitHub Desktop.
Clojure: Dynamic fn symbol
(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