cherry

borkdude 2022-08-08T12:44:44.769189Z

I'm having doubts about the Clojure namespace <-> ES6 output. I think it breaks down in what people expect from Clojure REPLs and also when mutating things in other namespaces with set!. I think cherry could still be useful for writing apps like you would in JavaScript (see examples). As such it could be a good tool to win JS developers over, but I'm having doubts if it can support the REPL experience (which is based on globally mutable vars in normal CLJS, JVM Clojure and (n)bb). Unless cherry outputs a completely different JavaScript in "dev" mode than it would in "production" mode. For dynamic vars I think there could be a way out by modelling them as mutable objects instead of just var x = ... , so something like var x = {val: ..} and then the other namespace could do x.val = ... so we could still have binding work properly.

2
borkdude 2022-08-08T13:06:53.001249Z

Thought experiment: What if vars were always compiled to globals:

(ns foo)
(def v 1)
would be compiled into:
cherry.namespaces.foo = {}
cherry.naemspaces.foo.v = 1
also foo.mjs would export { v } but then the module would just be a one-time snapshot of the true mutable namespace

borkdude 2022-08-08T13:09:30.516429Z

Something like this:

global.cherry = {namespaces: {}}

global.cherry.namespaces.x = 1;

let x = cherry.namespaces.x;

export { x }
It would break all treeshaking for everything that uses this output

Jimmy Miller 2022-08-08T13:48:52.405629Z

For what it's worth, I'd definitely expect a totally different format from dev to production and would not care at all about tree shaking and such in dev mode. So I like the idea.

💯 3
lilactown 2022-08-08T16:18:04.332129Z

I recommended something similar in the hot reloading issue https://github.com/borkdude/cherry/issues/25#issuecomment-1203238677

lilactown 2022-08-08T16:18:19.798459Z

I think it would work, but I haven't tried it

borkdude 2022-08-08T16:19:50.184889Z

That makes sense

2022-08-09T02:41:05.531279Z

I understand very little of JS modules.... But what if namespaces didn't map 1:1 to JS modules? What if there was a defmodule or something like that as well?

2022-08-09T02:42:19.556599Z

So if you wanted some cherry code used by some JS code, you would explicitly do something like:

(defmodule ModuleName
  {'default some/var
   'other-function some/other-var})