This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-05
Channels
- # announcements (1)
- # asami (1)
- # babashka (7)
- # beginners (11)
- # biff (2)
- # calva (7)
- # cider (1)
- # clara (5)
- # clj-kondo (223)
- # clojure (83)
- # clojure-boston (3)
- # clojure-conj (1)
- # clojure-europe (9)
- # clojure-uk (1)
- # clojurescript (11)
- # cursive (76)
- # emacs (30)
- # figwheel-main (2)
- # fulcro (13)
- # hyperfiddle (6)
- # lsp (6)
- # malli (2)
- # nyc (4)
- # off-topic (78)
- # practicalli (9)
- # reitit (4)
- # sci (20)
- # shadow-cljs (49)
- # sql (9)
- # xtdb (5)
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
.
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)}
@U050RLRRQ Are you talking about macros from .clj
or .cljs
?
so when you do it in a JVM on a normal function:
(defn ^:macro [])
will turn the function in a real JVM macrok thanks! I don’t think ^:sci/macro
works on a var, I believe I tried that awhile back
@U050RLRRQ should work now on master