This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-28
Channels
- # babashka (48)
- # babashka-sci-dev (7)
- # beginners (123)
- # calva (32)
- # cider (5)
- # clara (20)
- # clj-kondo (3)
- # cljdoc (2)
- # cljs-dev (1)
- # clojure (113)
- # clojure-dev (5)
- # clojure-europe (65)
- # clojure-norway (23)
- # clojure-spec (4)
- # clojure-uk (4)
- # clojurescript (33)
- # cursive (3)
- # datalevin (39)
- # datomic (2)
- # emacs (14)
- # events (1)
- # fulcro (10)
- # graphql (5)
- # humbleui (2)
- # integrant (4)
- # introduce-yourself (3)
- # jobs (1)
- # jobs-discuss (11)
- # kaocha (26)
- # leiningen (6)
- # malli (24)
- # nbb (2)
- # off-topic (69)
- # pathom (77)
- # podcasts-discuss (2)
- # reitit (8)
- # remote-jobs (2)
- # sci (17)
- # scittle (8)
- # squint (1)
- # xtdb (43)
Ok regarding macros -- I notice that the builtin macros like and
work no problem. Is that because they are baked into sci
at compile time?
in sci, you mean?
Of course -- so I'm rebuilding a huge amount of our application based on sci and I'm trying to understand the nuances better. In this case, why do some macros work and not others? I'm trying to learn sci best practices.
sure, let me work one up
ok so I know you wrote that great promesa toolkit, I'm just trying to understand the principle of why this doesn't work:
;; works
(sci/eval-form
(sci/init {})
'(do
;; defn is a macro
(defn foo [a b]
(+ a b))
(foo 1 2)))
;; doesn't work
(sci/eval-form
{:namespaces
{'promesa.core
(sci/copy-ns promesa.core
(sci/create-ns 'promesa.core))}}
'(promesa.core/let [a (js/Promise. (fn [resolve]
(resolve 1)))]
(println a)))
;;=> #object[Error Error: No protocol method IDeref.-deref defined for type undefined: ]
sorry I know this is contrived, just trying to understand the behavior better@goomba you can't really copy macros in CLJS since often they just live in the JVM or they are some weird runtime thing in CLJS which I still don't understand
There are some built-in things in SCI that are normally macros in Clojure, like and
and defn
- I've kept it that way for performance since they are used to frequently
So the best practice is: always make sure to re-define macros as functions in CLJS when you want to use them in your SCI context
oh weird :thinking_face:
but defmacro
works great in sci
(sci/eval-form
(sci/init {})
'(do
(defmacro hey []
`(+ 1 2))
(hey )))
;;=> 3
that means you wrote it yourself!