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.)
@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/
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)there's no in-ns but you can just write (ns foo) instead
I've done some work in the squint browser REPL, technically the same issues
here's the branch I worked on: https://github.com/squint-cljs/squint/tree/browser-nrepl
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
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
you could also try vite perhaps, then you might not have to do a full page reload
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
I'm familiar with vite but I think it's not as good as an actual REPL even with hot reloading
true
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
I'm fine with esbuild for now
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