sci

Lone Ranger 2022-09-28T17:57:35.665799Z

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?

borkdude 2022-09-28T17:58:18.805069Z

and is a built-in for performance

Lone Ranger 2022-09-28T17:58:57.242039Z

in sci, you mean?

borkdude 2022-09-28T17:59:15.002619Z

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

Lone Ranger 2022-09-28T18:00:40.511159Z

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.

borkdude 2022-09-28T18:01:20.688609Z

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

Lone Ranger 2022-09-28T18:02:01.626789Z

sure, let me work one up

Lone Ranger 2022-09-28T18:17:58.762449Z

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

borkdude 2022-09-28T18:21:00.905459Z

@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

borkdude 2022-09-28T18:22:06.277949Z

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

borkdude 2022-09-28T18:24:46.526709Z

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

borkdude 2022-09-28T18:26:37.562839Z

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 Ranger 2022-09-28T18:28:11.305739Z

oh weird 🤔

Lone Ranger 2022-09-28T18:28:42.976529Z

but defmacro works great in sci

Lone Ranger 2022-09-28T18:28:53.349159Z

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

borkdude 2022-09-28T18:29:12.327769Z

Yes it does

Lone Ranger 2022-09-28T18:30:03.487159Z

that means you wrote it yourself! wizard