This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-17
Channels
- # announcements (13)
- # beginners (56)
- # brompton (1)
- # cider (2)
- # cljsrn (10)
- # clojure (369)
- # clojure-australia (4)
- # clojure-boston (1)
- # clojure-europe (28)
- # clojure-nl (1)
- # clojure-spec (1)
- # clojure-uk (18)
- # clojurescript (26)
- # data-science (2)
- # datahike (4)
- # datalog (2)
- # datasplash (6)
- # datomic (9)
- # events (1)
- # kaocha (4)
- # macro (1)
- # malli (22)
- # meander (40)
- # membrane (30)
- # music (1)
- # nbb (3)
- # news-and-articles (3)
- # off-topic (12)
- # practicalli (1)
- # re-frame (19)
- # remote-jobs (1)
- # sci (22)
- # shadow-cljs (15)
- # spacemacs (4)
- # tools-deps (40)
- # xtdb (26)
Trying to wrap the macro http://reagent.co/with-let to be used in SCI, but when using it in eval, it seems to not understand it as a macro or something, as I'm getting a "Could not resolve symbol: t"
error with my example. My example execution looks like this: (with-let [t 10] [:div "Nah"])
which makes the error happen.
My SCI wrapper looks like this:
(def with-let ^:sci/macro
(fn [bindings & body]
`(r/with-let ~bindings ~@body)))
I tried with the [_&form _&env x]
argument definition as well from the README, but then it seems it swallows all the args somehow. Not sure what's going on@victorbjelkholm429 macros take two extra args indeed, those are mandatory
(def with-let ^:sci/macro
(fn [_ _ bindings & body]
`(r/with-let ~bindings ~@body)))
@borkdude thanks!
hm, maybe I'm adding the macro wrongly to the SCI context then? I'm using the :bindings
and then just refer to the function with the :sci/macro metadata.
Just tried this implementation:
(def with-let ^:sci/macro
(fn [form env bindings & body]
(pprint "Inside with-let")
(pprint form)
(pprint env)
(pprint bindings)
(pprint body)
`(r/with-let ~bindings ~@body)))
And I'm getting this as output:
"Inside with-let"
[]
[:div "Nah"]
nil
nil
If I pass it (with-let [] [:div "Nah"])
I don't understand why you are trying to produce r/with-let
though, I think you really have to (re-)implement the macro, not wrap it. But this is another problem.
yeah, seems form => binding vector and env ends up being body, so the two first args are not being used (by SCI?)
@borkdude tried this now:
(def with-let
(with-meta
(fn [form env bindings & body]
(pprint "Inside with-let")
(pprint form)
(pprint env)
(pprint bindings)
(pprint body)
`(r/with-let ~bindings ~@body))
{:sci/macro true}))
Same resultsThis should also work in CLJS:
(defn ^:macro with-let [_ _ bindings & body] ...)
(def rns (sci/create-ns 'reagent.core nil))
(def namespaces {'reagent.core {'with-let (sci/copy-var with-let reagent-ns)}})
(def ctx (sci/init {:namespaces namespaces}))
But so should:
(def with-let ^:sci/macro (fn with-let [_ _ bindings & body] ...))
(def namespaces {'reagent.core {'with-let with-let}})
(def ctx (sci/init {:namespaces namespaces}))
yeah, there is a lot of indirections at play (running Clojure code inside Obsidian via SCI), so trying to strip everything away