Skip to content

Instantly share code, notes, and snippets.

@thheller
Last active June 19, 2017 04:50
Show Gist options
  • Select an option

  • Save thheller/7dbd69a7aa4afae644d45e1c941a7883 to your computer and use it in GitHub Desktop.

Select an option

Save thheller/7dbd69a7aa4afae644d45e1c941a7883 to your computer and use it in GitHub Desktop.
(ns demo.macro-writing-macros)
(def dom-elements
'[h1
h2])
(defn gen-dom-macro [name]
`(defmacro ~name [p# & c#]
(let [kw# ~(-> name str keyword)
children# (into [] c#)]
`[~kw# ~p# ~children#])))
(defmacro define-element-macro []
`(do ~@(clojure.core/map gen-dom-macro dom-elements)))
(define-element-macro)
(prn (h1 {} "hello" "world"))
(prn (h2 {} "hello" "world"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment