I was searching around for examples again to figure out what the current recommended way to handle macros is. It seems like if I add ^:macro metadata to an ordinary defn, clojure sees it differently and I can’t call it normally anymore, so I can’t just pull out all my macro implementations into ^:macro-anotated versions that I can then directly add to sci via copy-var.
I am somehow confused about :macro and :sci/macro and how that fits together
right now I’m (a) pulling out my macro implementations into their own functions, and then (b) creating yet another function that I tag with ^:macro to copy-var into sci, and that seems like maybe more work than should be needed
eg.
;; implementation fn
(defn redef:impl [form env name & args] ...)
;; macro
(defmacro redef [name & args] (apply redef:impl &form &env name args))
;; sci version
(defn ^:macro redef:sci [form env name & args] (apply redef:impl &form &env name args))
;; elsewhere, adding to the namespace
{'redef (copy-var redef:sci the-ns)}@mhuebert Are you talking about macros from .clj or .cljs?
currently it’s a cljc project that works in both
so when you do it in a JVM on a normal function:
(defn ^:macro [])
will turn the function in a real JVM macrowhich is probably not what you want
does that redef:impl has to exist in the JVM context at all?
if not, ^:macro still works: #?(:cljs (defn redef:impl ^:macro [...]))
I'd have to check if ^:sci/macro also works on a var, but it's getting late now.
I'll check tomorrow
k thanks! I don’t think ^:sci/macro works on a var, I believe I tried that awhile back
we could maybe make that work
in copy var
yeah, I don't think there's anything wrong if we supported that
PR welcome
I'm fixing it right now
@mhuebert should work now on master