Skip to content

Instantly share code, notes, and snippets.

@mfikes
Created December 18, 2015 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfikes/1c2e701036e8caced17f to your computer and use it in GitHub Desktop.
Save mfikes/1c2e701036e8caced17f to your computer and use it in GitHub Desktop.
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