cherry

rads 2025-03-22T17:16:44.519989Z

I've been thinking about what it would take to set up a browser REPL for Cherry. Sending forms to the browser is the easy part, but it seems like the main blocker is that Cherry resolves symbols directly to the JS vars inside the ESM module. In contrast, the official CLJS compiler effectively resolves everything to top-level objects (using goog.provide to declare them), so it's possible to mutate those objects during REPL evaluation and treat those like Clojure namespaces. Since ESM modules don't have an API to redefine things internally, that's where we would need additional indirection from Cherry to be able to redef things. It would need to compile the symbols to resolve to a "namespace" instead of the direct JS accesses. Is this out-of-scope for Cherry? Is there another way to get a ClojureScript-like REPL experience in the browser? (IMO, replacing entire ESM modules at a time doesn't meet the bar.)

borkdude 2025-03-22T18:13:18.889239Z

@rads cherry supports :repl true to compile to REPL output. This is demoed directly in the playground which is effectively a REPL since you can compile forms incrementally: https://squint-cljs.github.io/cherry/

rads 2025-03-22T18:24:44.844999Z

Let's say I'm sending socket REPL commands to that browser REPL. There's no way to do this right now is there?

(in-ns 'foo)
(def a 1)

(in-ns 'bar)
(require 'foo)
(def b (inc foo/a))
(println b)

borkdude 2025-03-22T18:25:38.062219Z

there's no in-ns but you can just write (ns foo) instead

borkdude 2025-03-22T18:28:07.677339Z

I've done some work in the squint browser REPL, technically the same issues

borkdude 2025-03-22T18:29:00.518709Z

here's the branch I worked on: https://github.com/squint-cljs/squint/tree/browser-nrepl

rads 2025-03-22T18:31:45.281619Z

Cool, I'll take a look at this. I'd like to see if I can eventually set up a local nREPL server to talk to the cherry REPL so I can run my React app and send commands to it from within that REPL context

rads 2025-03-22T18:33:45.766149Z

Basically trying to replicate the shadow-cljs workflow. My app is already working well by reloading changes with a full page reload so this is more of a quality-of-life improvement. I know shadow-cljs uses piggieback on top of nREPL so I need to look into that a bit further but I'm trying to get something minimal working first

borkdude 2025-03-22T18:34:49.175379Z

you could also try vite perhaps, then you might not have to do a full page reload

borkdude 2025-03-22T18:35:37.535489Z

here's an example of such a setup: https://github.com/squint-cljs/squint/tree/main/examples/vite-react vite is a hot-reloader for JS

rads 2025-03-22T18:35:53.917099Z

I'm familiar with vite but I think it's not as good as an actual REPL even with hot reloading

💯 1
borkdude 2025-03-22T18:36:02.159239Z

true

rads 2025-03-22T18:36:13.089639Z

So I'd rather try to get that working and not add the complexity. IMO it's a good example of easy but not simple

rads 2025-03-22T18:36:19.822399Z

I'm fine with esbuild for now

rads 2025-03-22T18:38:52.879849Z

Plus I figure if I do get it working, others might benefit from having an example browser REPL that's ready to go for dev

❤️ 3