Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Illustration of compilation scope

In ClojureScript, macros can't be in the same thing from where they are consumed.

But thing is not "namespace", because ClojureScript functions can use macros from the same namespace.

And thing is not "file" because conditional compilation allows macros and consuming functions to be written in the same file. (See example below.)

In struggling to name this concept, the best I've come up with is compilation scope.

Here is the same file example. Assume this is src/foo/core.cljc:

(ns foo.core
  #?(:cljs (:require-macros [foo.core :refer [add]])))

#?(:clj 
  (defmacro add 
    [a b]
    `(+ ~a ~b)))

#?(:cljs
  (defn sum 
    [a b]
    (add a b)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment