Skip to content

Instantly share code, notes, and snippets.

@mhuebert
Last active November 9, 2016 14:29
Show Gist options
  • Save mhuebert/360fa2da97adac7756605b2d1438f753 to your computer and use it in GitHub Desktop.
Save mhuebert/360fa2da97adac7756605b2d1438f753 to your computer and use it in GitHub Desktop.
Macros that require macros, in ClojureScript. Remember, in your .clj file: use `:require` with `:include-macros true`
(ns app.x
(:require [app.y :refer [y-macro] :include-macros true]))
(defmacro x-macro [& args]
(y-macro args))
;; how can we use macros from one .clj namespace in another .clj namespace?
;; take a close look at the :require statement above. Two important points:
;; - it must say :require, not :require-macros
;; - it must say `:include-macros true`
(ns app.x
(:require-macros app.x))
;; cljs namespace requires same-name clj namespace
(ns app.y)
(defmacro y-macro [& args]
`[~@args])
;; this is a macro that I would like to use from within another macro namespace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment