This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-19
Channels
- # announcements (1)
- # babashka (40)
- # beginners (84)
- # biff (46)
- # calva (37)
- # cherry (2)
- # cider (18)
- # clj-otel (5)
- # clojure (53)
- # clojure-europe (39)
- # clojure-hungary (12)
- # clojure-norway (40)
- # clojure-sweden (2)
- # clojure-uk (2)
- # clojurescript (6)
- # community-development (21)
- # cursive (28)
- # data-science (12)
- # datomic (3)
- # figwheel-main (2)
- # fulcro (12)
- # graalvm (7)
- # gratitude (1)
- # hyperfiddle (23)
- # integrant (9)
- # jobs (2)
- # leiningen (4)
- # lsp (8)
- # malli (3)
- # missionary (1)
- # off-topic (39)
- # polylith (3)
- # portal (33)
- # practicalli (4)
- # re-frame (3)
- # releases (1)
- # sci (53)
- # solo-full-stack (8)
- # sql (5)
- # timbre (9)
I see SCI has support for Reagent. I would like to know whether I could make #C68M60S4F similarly compatible with SCI. What would it take & how to approach it? 🙏
The configuration has mostly to do with macros and dynamic vars. Here is the configuration for reagent: https://github.com/babashka/sci.configs/tree/main/src/sci/configs/reagent Feel free to contribute one for fulcro or let me know if you have other questions
I saw the config but did not really understand it 😅 Is there some guide for doing this? In particular, how do I find out what is it SCI needs help with? How can I test what works/doesn’t work? I am sorry, I am completely new to SCI …
I guess I could
(require '[sci.core :as sci])
(sci/eval-string "<some fulcro code>")
and see what breaks?
I guess I’d start with sci/create-ns
& friends to expose Fulcro code to SCI.I think I am starting to understand. I will get back here when I run into troubles.
right, I recommend creating a context first with (sci/init ..)
and then use (sci/eval-string ctx "...")
the challenge is mostly macros, which aren't available in cljs so you have to port them to normal functions and add ^:sci/macro
metadata on those
@U050RLRRQ actually has a macro somewhere that allows you to define a macro for both JVM Clojure, CLJS and SCI
so copying the macros, changing them to regular functions and then adding ^:sci/macro
metadata to it will work
thanks a lot!
Q: Is it possible to find out the name of the current namespace in a sci macro? When I look it &env
it is just {}
and thus there is no (:ns &env)
. Similarly, *ns*
is nil.
in JVM Clojure, &env doesn't contain the current namespace, macros in SCI work similar to JVM Clojure
SCI does not affect the host system's *ns*
- in general, it doesn't mutate the host environment
A demo:
cljs.user=> (defn ^:sci/macro foo [_ _] [(str (deref sci.core/ns)) `(str *ns*)])
#'cljs.user/foo
cljs.user=> (def ctx (sci/init {:namespaces {'foo {'foo (sci/copy-var cljs.user/foo (sci/create-ns 'foo))}}}))
#'cljs.user/ctx
cljs.user=> (sci
The foo macro both derefs the current SCI namespace at "expansion" time and at "runtime" (the last bit is evaluated after expansion)
whoops, copy/paste wasn't complete:
cljs.user=> (sci/eval-string* ctx "(foo/foo)")
["user" "user"]
ah here was the macro to define macros for both regular clojure and SCI at the same time: https://github.com/mentat-collective/emmy/blob/e16b5692b04972f0bc9ea6d07f7ead41edccc066/src/emmy/util.cljc#L141
Nice! Though ☝️ wouldn’t help me, since I need to use sci.core/ns instead of (:ns &env) / *ns*
What’s the best practice for writing custom SCI configs like https://github.com/babashka/sci.configs/blob/main/src/sci/configs/reagent/reagent.cljs ? I am rewriting a rather involved https://github.com/fulcrologic/fulcro/blob/main/src/main/com/fulcrologic/fulcro/components.cljc#L1372 (or rather the fn it delegates to), which calls bunch of fns etc. Prefixing all the calls with the original ns seems as unnecessary work, if I could simply do
(ns com.fulcrologic.fulcro.components)
(defn defsc*-for-sci [..] ...)
inside the custom settings ns. WDYT?Damn, it doesn’t work in cljs 😭
What do you mean?
Hm, this is turning into a nightmare. Fulcro is using plenty of #?(:clj ...)
code used by its central macro, meaning that I’d need to rewrite all of it if I wanted to be able to run in SCI 😭
I will look into it. Though most of these are functions (called from a macro). But at least a similar approach should be possible…
@borkdude Q about SCI 0.7.39 - SCI on cljs seems to not respect unquotes?
this is running in Clerk, via their editor example
can't reproduce:
cljs.user=> (sci/eval-string "(let [x 10] `(+ ~x ~x))")
(clojure.core/+ 10 10)
it might be that they are parsing on their own using edamame and haven't enabled :syntax-quote
or some other issue, it seems rewrite-clj is part of the mix too, I'd just submit a clerk issue
perhaps you can intercept the string that is being evaluated by the editor to see what goes in
I see you mentioned 2.maria in your emmy announcement, has this had a proper announcement itself once? I wondered about its progress :)
haha I don’t think it has, I am leaking it 🙂
I bet you’re right that it’s an edamame thing
I love these little executable gists
I suspect the issue might be elsewhere, please just intercept the string that gets fed into sci/eval-string first, to determine if this is not a rewrite-clj issue which I see is also used
anyway, I'm not clear on what happens and short on time (packing bags). perhaps you can make smaller repros and I'll have a look again
What’s the best practice for writing custom SCI configs like https://github.com/babashka/sci.configs/blob/main/src/sci/configs/reagent/reagent.cljs ? I am rewriting a rather involved https://github.com/fulcrologic/fulcro/blob/main/src/main/com/fulcrologic/fulcro/components.cljc#L1372 (or rather the fn it delegates to), which calls bunch of fns etc. Prefixing all the calls with the original ns seems as unnecessary work, if I could simply do
(ns com.fulcrologic.fulcro.components)
(defn defsc*-for-sci [..] ...)
inside the custom settings ns. WDYT?