Fork me on GitHub
#sci
<
2022-03-03
>
baibhavbista07:03:21

How do I get macros from other namespaces working in sci in cljs? I found the following script to copy a namespace to sci https://github.com/babashka/sci#copy-a-namespace

(reduce (fn [ns-map [var-name var]]
            (let [m (meta var)
                  no-doc (:no-doc m)
                  doc (:doc m)
                  arglists (:arglists m)]
              (if no-doc ns-map
                  (assoc ns-map var-name
                         (sci/new-var (symbol var-name) @var
                                      (cond-> {:ns fns
                                               :name (:name m)}
                                        (:macro m) (assoc :macro true)
                                        doc (assoc :doc doc)
                                        arglists (assoc :arglists arglists)))))))
          {}
          (ns-publics 'foobar))
The bit with (:macro/m) makes me think that it should transfer macros as well. However, doing (ns-publics 'cljs.core.async) does not seem to return the macros like go, go-loop. Am I missing something?

baibhavbista07:03:10

I'm on org.babashka/sci {:mvn/version "0.2.8"}

baibhavbista07:03:32

I'm trying to get cljs.core.async and cljs.core.async.interop to work on sci. Is that possible?

borkdude07:03:14

core.async doesn't even work in self-hosted CLJS.

borkdude07:03:36

I recommend using promesa for async programming in CLJS. See #nbb which has a config for that.

borkdude07:03:00

In general, you can include a macro like this:

(defn ^:macro foo [_ _] `(do (+ 1 2 3)))

(def sci-ns (sci/create-ns 'foobar))
{'foo (sci/copy-var foo sci-ns)}

borkdude07:03:24

Usually you have to re-implement the macro to be available in CLJS at runtime as a function, like that.

baibhavbista08:03:54

majority of promesa's stuff (like the let) is also implemented as macros, no?

baibhavbista08:03:10

ohhh you have to write kind of a wrapper macro to get it to work?

baibhavbista08:03:01

However, you have already done the work for almost everything I would want...I can just copy your code. Thanks a ton @U04V15CAJ !!

borkdude08:03:22

Yeah please go ahead and copy it :)

❤️ 1
baibhavbista08:03:55

It works great, thank you 😁

🎉 1
borkdude17:03:25

@baibhavbista I'm adding ready to be used configs to this repo: https://github.com/babashka/sci-configs#funcoolpromesa So all you have to do is include that project and then use the config.

❤️ 1
baibhavbista02:03:58

btw there seems to be a typo.. the namespace is reagent for the js-interop one too 😅

borkdude10:03:43

Thanks, fixed