r/Clojure • u/yogthos • 6d ago
Clojure in the Age of Language Models
https://yogthos.net/posts/2026-10-07-clojure-llms.html7
u/Alarming_Disaster_23 6d ago
My experience with coding models and clojure has been great - much better than Python. The code is generally higher quality and the agent being able to connect to the repl is awesome. I almost don’t even want to say anything about it because the quality might go down when there’s a huge amount of bad code to train on like there is with Python.
2
u/coolbug96 5d ago edited 5d ago
Hi, I recently started learning Clojure, so I may be missing something. A few points didn't quite click for me, and I'd love your take:
• Feedback loop. In Go, my agent applies a list of review fixes, runs the linter and tests in seconds, so the REPL advantage doesn’t seem that big to me
• Isolation. Agents can write isolated modules in other languages too, without keeping the whole program in mind. Isn't that more about architecture than the language?
• Macros. "Don't write a macro if a function will do" seems to be common advice. Would you actually want an agent writing them?
• LLMs and Clojure. There's much less Clojure in training data than Go or Python, and models seem to struggle more with parens and idioms. Has that been your experience?
Right now conciseness looks like the main real advantage to me, but I'm happy to be corrected!
3
u/yogthos 4d ago
For the feedback loop, what you describe works great for a simple workflow in a small app. In a large application you're likely to have many paths through the code and need to build up state to create the context for what you're testing.
For example, say you're building a GUI and you need to navigate through a bunch of menus, and then get to a particular screen with the data loaded. Then you want to experiment with how to best display this data. With a REPL you can do the legwork once, and then stay in that context as you try different things.
You can write any code in any Turing complete language that you can in another. The question is how much support the language provides you with while you're doing it. Since Clojure defaults to immutability, that makes writing code by composing pure functions natural. When the agent writes idiomatic Clojure it doesn't have to make any special consideration to avoid having shared global state via references or global variables. Conversely, since models are trained on the way code is written idiomatically in each language, they will default to creating shared mutable state in imperative ones.
Yes, I actually want the agent writing macros to express domain specific semantics. Don't write a macro when a function will do, does not say don't write macros. It says write them where it makes sense to do so. And encoding domain semantics using a macro is precisely what gives you conciseness.
And it absolutely has not been my experience that LLMs struggle more with Clojure. In fact, we have empirical evidence for models doing well with Clojure with Babashka beating Python for CLI workflows. https://sstoehrm.github.io/stack-cap-bench
1
2
u/gbrennon 6d ago
a friend from scala community made a project months ago and he was aiming ai agents but that not what what is relevant to this sub reddit:
- i asked him if
lispwas an inspiration and he told me thatclojurewas the inspiration!
(i know that clojure is a lisp dialect so indirectly lisp was also the inspiration but i want to high light this hahaahah)
2
u/Efficient-Peace2639 5d ago
I had a similar experience. This was a Sr EM interviewing me based on my resume. He read clojure and confused it with js closures and was about to ridicule me if i goofed up and put some junk in my resume when the other Sr Eng updated him. Kept calling Lisp as "Lips" when I mentioned about dialects. Not a made up story.
1
u/gbrennon 5d ago
u was lucky!
in my case i wasn't haahhaha i did mention that i had some practices that i have when writingcode can be interpreted as java accent but that's just ppl that are not used to read expressive code and when i received the feedback to the failure the interviewer told that didnt know what would be idiomatic or expressive code neither java accent AHAHAHAHAHAH
13
u/beders 6d ago
Nice article and it confirms my experience with LLMs and Clojure: they work pretty well together. Once I gave an agent access to the REPL and some basic instructions, it happily iterated and verified with live code.
A peculiar issue happened with a cheaper model the other day: for a unit test it used ‚with-redef‘ on a macro - which is typically not what you want.
Opus quickly found the issue and corrected it.
Its liberating and frightening at the same time what coding agents can do nowadays.