Skip to content

Instantly share code, notes, and snippets.

@cgrand cgrand/core.cljc
Last active May 11, 2018

Embed
What would you like to do?
Mixing macros and code in cljc and supporting clj, cljs and self-hosted cljs, see https://github.com/cgrand/macrovich
;; SEE: https://github.com/cgrand/macrovich
;; macros and code in a single cljc working across clj, cljs and self-hosted cljs
;; require clojurescript from master
(ns foo.core
#?(:cljs (:require-macros
[net.cgrand.meta-macros :refer [macros no-macros]]
[foo.core :refer [add]])
:clj (:require
[net.cgrand.meta-macros :refer [macros no-macros]])))
(macros
(defmacro add
[a b]
`(+ ~a ~b)))
(no-macros
(defn sum
[a b]
(add a b)))
;; SEE: https://github.com/cgrand/macrovich
(ns net.cgrand.meta-macros)
(defmacro macros [& body]
#?(:cljs
(when (re-matches #".*\$macros" (name (ns-name *ns*)))
; bootstrapped cljojurescript macro
`(do ~@body))
:clj ; clj or cljs/jvm
(when-not (:ns &env)
`(do ~@body)))) ; clj
(defmacro no-macros [& body]
#?(:cljs
(when-not (re-matches #".*\$macros" (name (ns-name *ns*)))
`(do ~@body)) ; any cljs non-macro
:clj ; clj or cljs/jvm macro
`(do ~@body)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.