clojure

Jim Newton 2026-03-20T09:26:41.722929Z

is there some way to ask a live clojure session whether some file has changed since it was most recently loaded? Sometimes during editing I forget to reload some code I changed, and it is really difficult to figure out which. So I end up just restarting. Not the end of the world, but if there’s an easier way it could help.

p-himik 2026-03-20T09:29:56.647709Z

So I end up just restarting.Can always reload everything. > Sometimes during editing I forget to reload some code I changed Exactly where the "reloaded" workflow shines. :D I haven't tracked what exactly I changed in years. And to answer the question - nothing built-in. But there are libraries that do it, e.g. https://github.com/tonsky/clj-reload.

✔️ 3
Bailey Kocin 2026-03-20T12:59:36.850149Z

I tend to use things built into my text editors to "reload namespace on save" type of deal. Calva supports this with some vscode settings so thats what I do.

p-himik 2026-03-20T13:12:29.254749Z

"On save" can be a bit finicky when you save a file that depends on another, unsaved, file. Also conflicts somewhat with the "save on the editor losing focus" approach. But it's good if those aren't a concern for you.

Steven Lombardi 2026-04-10T04:43:58.652469Z

I'm a big fan of tools.namespace for managing this.

practicalli-johnny 2026-03-22T08:53:04.878259Z

For visually tracking evaluated code, Emacs Cider marks code that has been evaluated in the margin. The mark is removed when the code is changed. In my view, loading (evaluating code) is an editor/user aspect. I eval code as I change it, that way I get feedback straight away. Code that is expetimental or expected to break is done within a rich comment form until ready.

Jim Newton 2026-03-20T11:30:33.397599Z

I’m looking for some examples of using clojure.test to test for exceptions thrown by (throw (ex-info …)) … I’ve already asked chatgpt, but I don’t think it has given me the correct information. In particular I want to assert that the following code was encountered/executed. I’d prefer to check for the :code but I’d settle for matching the string error message.

(throw (ex-info (cl-format false "transitions ~A has a duplication of types: ~A"
                                     transitions (find-duplicates types))
                          {:transitions transitions
                           :code :xymbolyco-493
                           :duplicates (find-duplicates types)}))

p-himik 2026-03-20T11:38:09.455079Z

With clojure.test you can conveniently check only for the class of the thrown exception, with (is (thrown? TheExClass (something ...)). If you need a much more in-depth check, specifically for the (ex-data ...), you can always do something like this:

(try
  (something-that-should-throw)
  (is false "not thrown")
  (catch Exception e
    (let [data (ex-data e)]
      ...all the checks...)))

Jim Newton 2026-03-20T11:39:31.312909Z

yes I’d like to distinguish between two different but similar errors to make sure they are each handled correctly. chatgpt suggested thrown-with-msg? does that ring a bell?

Jim Newton 2026-03-20T11:45:16.111779Z

ahhh I figured it out. I was tying to include thrown-with-msg? into the require …

lassemaatta 2026-03-20T11:51:02.295479Z

I think someone recently suggested that is returns the tested value so you can alternatively do something like (let [ex (is (thrown? SomeException ..)) data (ex-data ex)] )

👍 1
👍🏻 1
Max 2026-03-20T12:31:50.499059Z

https://github.com/nubank/matcher-combinators also offers better support for asserting about ex-data

➕ 2
Jim Newton 2026-03-20T12:32:48.273779Z

it is interesting that as soon as I tried to test for expected exceptions, I started finding bugs in my code. so just a little bit of testing helps a lot.

dpsutton 2026-03-20T13:47:28.180779Z

i sometimes just go more manual rather than the thrown with message style

(let [e (try (f)
             (is? false "didn't throw")
             (catch Exception e e))]
  (is (= {} (ex-data e))))
then you can do all the assertions on type, ex-data, message, whatever you want

👍🏻 1
Jim Newton 2026-03-21T11:14:35.408119Z

yes, in that case it’s pretty easy for me to write my own macro to do what I want.