This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-03
Channels
- # announcements (3)
- # babashka (29)
- # beginners (95)
- # calva (109)
- # cider (16)
- # clj-kondo (6)
- # cljdoc (2)
- # cljsrn (2)
- # cljtogether (1)
- # clojure (85)
- # clojure-europe (26)
- # clojure-india (1)
- # clojure-seattle (1)
- # clojure-uk (6)
- # clojurescript (14)
- # conjure (4)
- # cursive (8)
- # datomic (6)
- # emacs (21)
- # events (1)
- # figwheel-main (5)
- # fulcro (11)
- # graalvm (32)
- # graphql (1)
- # holy-lambda (7)
- # humbleui (7)
- # jobs (3)
- # membrane (8)
- # nextjournal (31)
- # off-topic (29)
- # pathom (14)
- # polylith (6)
- # portal (16)
- # practicalli (4)
- # reitit (17)
- # releases (1)
- # remote-jobs (2)
- # ring (4)
- # sci (20)
- # shadow-cljs (24)
- # sql (1)
- # vim (12)
- # xtdb (3)
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?I'm on org.babashka/sci {:mvn/version "0.2.8"}
I'm trying to get cljs.core.async and cljs.core.async.interop to work on sci. Is that possible?
I recommend using promesa for async programming in CLJS. See #nbb which has a config for that.
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)}
Usually you have to re-implement the macro to be available in CLJS at runtime as a function, like that.
Ohh okay
majority of promesa's stuff (like the let
) is also implemented as macros, no?
Not the majority, but quite a few: https://github.com/babashka/nbb/blob/main/src/nbb/promesa.cljs
ohhh you have to write kind of a wrapper macro to get it to work?
However, you have already done the work for almost everything I would want...I can just copy your code. Thanks a ton @U04V15CAJ !!
@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.
thenks @U04V15CAJ 😄
btw there seems to be a typo.. the namespace is reagent for the js-interop one too 😅