clojure

Jim Newton 2026-06-02T10:06:37.341369Z

I just discovered something I should have already known. I’m sometimes using (System/exit 0) to exit immediately from a script written in clojure because otherwise it takes far to long to quit. However, if there is anything that has been printed using printf which hasn’t been actually flushed to stdout, then it gets lost. Therefore it seems one should always call flush before calling System/exit.

Ed 2026-06-02T10:12:29.168519Z

Why does it take too long to exit? Maybe you need to call this? https://clojuredocs.org/clojure.core/shutdown-agents

borkdude 2026-06-02T10:12:57.394589Z

or use babashka for scripting, it not only quits fast, it also starts fast babashka 😅

💯 4
😂 2
p-himik 2026-06-02T10:15:26.480849Z

An extension to that is that you can have exactly one (System/exit 0), which is implicit - by letting the body of the main function end. Doing that while still having early interrupts can be achieved with exceptions that you catch in -main, maybe report, and exit with a (flush). A beneficial side-effect is that you can also call any procedure that wants to exit early without exiting the whole program. So, you can use it from other scripts, have retries, use it from a REPL.

borkdude 2026-06-02T10:16:15.214249Z

I was just adding an *exit-fn* hook to one of my libraries so (System/exit 1) won't be called in the REPL

p-himik 2026-06-02T10:18:03.451149Z

So, you'd call it like (*exit-fn* 1) instead, and make it be System/exit in scripts and something like #(throw (ex-info "stopping early" {:status %})) in REPL?

borkdude 2026-06-02T10:18:17.908849Z

yeah

borkdude 2026-06-02T10:19:03.986199Z

I have a similar thing in deps.clj

Jim Newton 2026-06-02T10:23:31.657969Z

> or use babashka for scripting, it not only quits fast, it also starts fast I’ve never used babashka. and I’ve never had problems with startup time. That being said, I’m not opposed to refactoring my code to use babashka if there are some interesting benefits. However, I’d need some help (from a human being).

borkdude 2026-06-02T10:24:12.403959Z

@jimka.issy I was half-joking. If you don't have a problem, keep on going :) But if you do need help, #CLX41ASCS is available for you.

borkdude 2026-06-02T10:24:51.182829Z

I was just triggered by the word "script". that's bb's main thing

Jim Newton 2026-06-02T10:25:28.898999Z

> Why does it take too long to exit? Maybe you need to call this? I put the System/exit in my code long ago. I don’t remember exactly what was triggering the slowness. Is that something you’d (@ed) recommend investigating tracking down?

borkdude 2026-06-02T10:26:04.701289Z

that's what ed already mentioned, you should look into shutdown-agents. you're likely using a promise or future somewhere which triggers those threadpools

Jim Newton 2026-06-02T10:28:20.876959Z

@borkdude > If you don’t have a problem, keep on going on the other hand, one (me) shouldn’t use that excuse for avoiding learning something new. I more and more find it easier to write scripts in clojure than in python, especially when it is just me who will be using them. However, I prefer writing the scripts in python if I’m going to distribute them to other people, especially to my students.

borkdude 2026-06-02T10:29:32.921739Z

makes sense. on the other hand, your clojure students may also enjoy writing scripts for themselves in clojure

Ed 2026-06-02T10:37:41.760639Z

I seem to recall that you (@jimka.issy) were doing something with long running processes running your student's code on a threadpool or something? If it's that, then you probably need to shut that threadpool down when you want to exit? Just finishing the main thread doesn't necessarily stop all the other threads from running.

Jim Newton 2026-06-02T10:38:28.260869Z

@borkdude I have two sorts of students at the moment. 1) Students of my Functional programming techniques in Clojure course. and 2) first year math and informatics students. The FP students might indeed be interested. However, for the 1st year students, it would be far over their heads.

borkdude 2026-06-02T10:39:22.426649Z

sure, you can decide if it's suited for them once you know how to use it yourself

👍🏻 1
Jim Newton 2026-06-02T10:39:46.722439Z

BTW, I submitted a proposal for presentation for clojure.conj to report on my FP in clojure course. do you have an oracle to predict who’ll be accepted and who’ll be cast into the deep?

borkdude 2026-06-02T10:40:23.869229Z

I'm afraid bb can't help you with that... unless... you teach them bb and also report about that, maybe it'll give some juice to the talk :P

borkdude 2026-06-02T10:41:17.077339Z

but seriously no, that process is shielded from me :)

neumann 2026-06-02T17:59:16.297809Z

@jimka.issy Despite being involved in the CFP process, I don't have an oracle either, but if you DM me your abstract, I can give you feedback to point out anything I notice that would hurt its chances of being accepted.

rwaweber 2026-06-02T13:08:55.126859Z

Hey all! Just confirming some language on the deps.edn https://clojure.org/reference/deps_edn#procurer_mvn page - are :mvn/repos evaluated in order? E.g., a dependency not found in central would then be checked in clojars? (following the reference example) Similarly, would an override of central in a project's deps.edn encourage the artifact resolver(probably not the right term) to check their first? I'm trying to sort out some artifact repository priority and just want to make sure I have my arms around some of the tradeoffs if we move to an internal cache

2026-06-02T13:23:59.256029Z

they're defined in hashmaps so there's no predetermined order in that respect. that a given map may or may not be an "array-map" doesn't mean you can expect or assume that it will stay that way

Alex Miller (Clojure team) 2026-06-02T13:28:17.688399Z

They are not ordered but the built in repos central and clojars are always checked first, in that order

Alex Miller (Clojure team) 2026-06-02T13:31:20.085569Z

If you move to an internal repository (a great idea), you should use the built-in Maven proxy feature - this is used by tools.deps/CLI

Alex Miller (Clojure team) 2026-06-02T13:35:29.406829Z

If needed, you can “remove” the central repo by setting it to nil in the deps map

rwaweber 2026-06-02T13:39:40.496229Z

Gotcha, that makes sense! Thanks a ton Noah and Alex!

👍 1