Fork me on GitHub
#cursive
<
2022-08-06
>
Kamuela16:08:50

Should my workflow be save to editor and then Restart REPL? Or am I missing something fundamental?

Kamuela17:08:05

Sync files in REPL is likely what I'm looking for then

Kamuela17:08:12

Maybe not... I dunno, that restart REPL does feel like a heavy operation, but it kinda does what I expect

Alex Miller (Clojure team)17:08:30

there are a few different ways people work (restarting the repl is not one of them)

1
Alex Miller (Clojure team)17:08:57

some people only (or mostly) evaluate individual expressions from the editor

Alex Miller (Clojure team)17:08:46

that page does not seem to cover that, but there are actions to evaluate the prior form at the cursor or top level form you're in

Alex Miller (Clojure team)17:08:16

often people work like this in (comment ) blocks in the file they're in

Alex Miller (Clojure team)17:08:33

other people tend to reload the current file as they edit (load file in repl) ... this is my typical mode of working. I'm not sure it's the best, but it is a habit I developed long ago

Alex Miller (Clojure team)17:08:00

and then other people follow the mode of "refreshing" or "syncing" the repl by reloading all changed files. you might also see this called the "reloaded" pattern. Cursive's "Sync files in REPL" seems to be of this mode. I didn't even realize Cursive had that, but I've never used it.

Alex Miller (Clojure team)17:08:37

typically I find that just reloading the current file is sufficient for me to have the repl runtime state "follow" my changes. there are a few well-known cases where the Clojure runtime stores things that can go stale - namely protocol and multimethod implementations, well and I guess things like defonce. if you are reloading a sufficient set of files and have a good mental model of how those work, you can avoid issues there. in last case, I'll restart.

Kamuela17:08:41

I removed a function and added a dummy function called thing, and when I did the sync files after removing it, it remained in the REPL. When I restarted the REPL, it was gone. That's what I'm noticing with sync files. Is that expected behavior? Because I, too, am banking on sync files to be the way to go, but that's strange behavior, and if I restart the REPL, I get what I expect

Kamuela17:08:17

Also, perhaps in a larger project restarting the REPL would be a heavy operation, but it takes under a second in my toy situation at the moment

Kamuela17:08:45

Load file in REPL also keeps removed functions. Perhaps that makes sense to people and I just need to change my expectation?

Kamuela17:08:27

In the case of changing an implementation, I confirm that both sync and load do reflect those changes. So maybe it's not an issue

Alex Miller (Clojure team)17:08:58

that is expected - the clojure runtime stores state across the set of loaded namespaces, which have vars, which have state. syncing and reloading will re-populate that state, but won't generally remove it.

Alex Miller (Clojure team)17:08:37

there are ways to remove vars, like (ns-unmap *ns* 'fn-to-remove)

Alex Miller (Clojure team)17:08:13

the reloaded workflow actually unloads, then reloads to avoid this. generally, I do not find that to be worth doing. if I remove enough stuff that it's annoying me (like renaming a bunch of tests), then I'll restart the repl

metal 1
Jordan Robinson20:08:17

Related; is there a nice way to list what's loaded and, crucially, when it was loaded in? I tend to use re-run last test in repl a lot, and it does seem to sometimes miss things. At the minute I just restart repl if things seem off, but if there's a way to avoid that it would be great

dpsutton20:08:31

(comment (require ‘the-ns :reload)) can give you confidence

cfleming21:08:40

That doc page about using the REPL could really do with some love.

salam00:08:56

have you thought about crowdsourcing the Cursive doc? 🙂

cfleming06:08:12

So, yes I have. What’s holding me back at the moment is that the build of the doc is very complicated. Maintaining the screenshots was a nightmare, so I now script and automate the IDE to take them, and take them with a frankentool which calls Apple APIs directly. So now it’s a different sort of nightmare 🙂

cfleming06:08:42

To be clear, it’s much much better, but it would be hard to get someone other than me using it.

👍 1