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?
and is a built-in for performance
in sci, you mean?
Can you reformulate your question? I'm not sure if I understood correctly
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.
What is your definition of "work"? What doesn't work? Repro?
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
this is the reason why the promesa config looks like it looks
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 🤔
but defmacro works great in sci
(sci/eval-form
(sci/init {})
'(do
(defmacro hey []
`(+ 1 2))
(hey )))
;;=> 3
Yes it does
that means you wrote it yourself! wizard