Fork me on GitHub
#sci
<
2022-09-28
>
Lone Ranger17:09:35

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?

borkdude17:09:18

and is a built-in for performance

Lone Ranger17:09:57

in sci, you mean?

borkdude17:09:15

Can you reformulate your question? I'm not sure if I understood correctly

Lone Ranger18:09:40

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.

borkdude18:09:20

What is your definition of "work"? What doesn't work? Repro?

Lone Ranger18:09:01

sure, let me work one up

Lone Ranger18:09:58

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

borkdude18:09:00

@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

borkdude18:09:06

this is the reason why the promesa config looks like it looks

borkdude18:09:46

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

borkdude18:09:37

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

Lone Ranger18:09:11

oh weird :thinking_face:

Lone Ranger18:09:42

but defmacro works great in sci

Lone Ranger18:09:53

(sci/eval-form
 (sci/init {})
 '(do
    (defmacro hey []
      `(+ 1 2))
    (hey )))
;;=> 3

borkdude18:09:12

Yes it does

Lone Ranger18:09:03

that means you wrote it yourself! wizard