sci

Sam Ritchie 2023-01-27T21:40:44.734089Z

@borkdude I think it’s finally time to replace my code here https://github.com/mentat-collective/emmy/blob/main/src/emmy/env/sci.cljc#L21-L42 with calls to sci/copy-ns… I’m reading the code and wondering if macros are simply ignored by this, or if there is some fancier way to handle them?

Sam Ritchie 2023-01-27T21:41:46.675589Z

also curious @borkdude if it’s possible for dynamic variables to work inside of SCI; meaning, if I have a dynamic var outside, will the copied version from copy-ns be appropriately dynamic

Sam Ritchie 2023-01-27T21:42:28.647169Z

anyway cleaning this up will be a great upgrade

borkdude 2023-01-27T22:04:55.669119Z

yes, dynamic vars will be also dynamic in SCI but they won't be synchronized with the dynamic var they were copied from, you have to do this manually

Sam Ritchie 2023-01-27T21:43:27.724379Z

I’m also curious what you think about the pattern of exposing, for example, this namespaces map as part of my library: https://github.com/mentat-collective/mafs.cljs/blob/main/dev/mafs/clerk_ui.cljs#L18-L34 the only downside I can see to putting that map into its own namespace is that I would gain an extra dependency on SCI; I don’t see a way to exclude it.

Sam Ritchie 2023-01-30T19:36:10.796399Z

@borkdude the only thing I’m thinking of adding to this pattern is

(defn install! []
  (sci.ctx-store/swap-ctx!
   sci/merge-opts
   config))

borkdude 2023-01-30T19:42:06.936209Z

that's what I do a lot too :)

Sam Ritchie 2023-02-01T14:59:17.424119Z

if I made a namespace that actually called this function, the the user wouldn’t have to write any cljs at all, just include emmy.sci-install in their list of required namespaces, and keep stacking namespaces to get more plugins…

Sam Ritchie 2023-02-01T15:00:18.207929Z

is there any merit to that pattern? or is there some way we could take a data config into Clerk, like :plugins, :aliases etc and then generate a cljs file that does this, without the user having to write a cljs file?

borkdude 2023-02-01T15:02:54.396979Z

I think it might be better to have the explicit install since the namespace loading order matters and there might not be a sci context in the sci ctx-store yet

Sam Ritchie 2023-02-01T15:03:19.855089Z

yeah, you’re right. There is that mysterious side effecting import of Clerk’s sci-env that needs to happen too.

Sam Ritchie 2023-02-01T15:03:40.952789Z

“mysterious” from the perspective of someone experiencing Clojure for the first time via Clerk, I mean

Sam Ritchie 2023-01-27T21:44:21.614209Z

but it feels like it’d be a great pattern for all of these reagent plugin libraries i’ve been building to following some convention for installing their namespaces into the SCI context. then users can add their own aliases of cousre

Sam Ritchie 2023-01-27T21:47:00.982479Z

would there be a bundle size penalty for copying everything at compile time? maybe not, if I do something like

(defn get-namespaces [{:keys [exclusions]}]
  (-> {'mafs
       (sci/copy-ns mafs (sci/create-ns 'mafs))
       
       'mafs.coordinates
       (sci/copy-ns mafs.coordinates (sci/create-ns 'mafs.coordinates))

       'mafs.plot
       (sci/copy-ns mafs.plot (sci/create-ns 'mafs.plot))

       'mafs.line
       (sci/copy-ns mafs.line (sci/create-ns 'mafs.line))

       'mafs.debug
       (sci/copy-ns mafs.debug (sci/create-ns 'mafs.debug))

       'mafs.vec
       (sci/copy-ns mafs.vec (sci/create-ns 'mafs.vec))}
      (dissoc exclusions)))
?

borkdude 2023-01-27T22:06:33.085309Z

You can make these SCI configurations available as an optional dependency, either by putting them inside namespaces that are optional to load or in a different library. I've done that with configs I use frequently here: https://github.com/babashka/sci.configs

Sam Ritchie 2023-01-27T22:08:27.753369Z

Oh, and because it’s cljs … you’re saying just don’t ship the dependency and leave it up to the user

Sam Ritchie 2023-01-27T22:08:39.870289Z

Nice!

Sam Ritchie 2023-01-27T22:09:57.600999Z

@borkdude do you know if that convert above matters at all - like if that optional namespace binds a var with a bunch of different namespaces, and the user only wants 1/100 or something, will that blow up the build?

Sam Ritchie 2023-01-27T22:10:06.594779Z

or is Closure smart enough to trim the unused ones?

borkdude 2023-01-27T22:10:37.353309Z

closure is smart enough

❤️ 1
borkdude 2023-01-27T22:11:21.165569Z

you can test this yourself using the shadow-cljs build report

Sam Ritchie 2023-01-27T22:23:49.449559Z

TIL, awesome