Fork me on GitHub
#sci
<
2023-03-05
>
mhuebert22:03:08

@borkdude I’m able to copy-ns that problematic namespace now

🎉 2
mhuebert22:03:41

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.

mhuebert22:03:03

I am somehow confused about :macro and :sci/macro and how that fits together

mhuebert22:03:45

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

mhuebert22:03:42

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)}

borkdude22:03:31

@U050RLRRQ Are you talking about macros from .clj or .cljs?

mhuebert22:03:49

currently it’s a cljc project that works in both

borkdude22:03:21

so when you do it in a JVM on a normal function:

(defn ^:macro [])
will turn the function in a real JVM macro

borkdude22:03:43

which is probably not what you want

borkdude22:03:14

does that redef:impl has to exist in the JVM context at all?

borkdude22:03:51

if not, ^:macro still works: #?(:cljs (defn redef:impl ^:macro [...]))

borkdude22:03:28

I'd have to check if ^:sci/macro also works on a var, but it's getting late now.

borkdude22:03:33

I'll check tomorrow

mhuebert22:03:50

k thanks! I don’t think ^:sci/macro works on a var, I believe I tried that awhile back

borkdude22:03:31

we could maybe make that work

borkdude22:03:42

in copy var

borkdude22:03:01

yeah, I don't think there's anything wrong if we supported that

borkdude09:03:44

I'm fixing it right now

borkdude09:03:17

@U050RLRRQ should work now on master