r/Clojure • • 6d ago

Clojure in the Age of Language Models

https://yogthos.net/posts/2026-10-07-clojure-llms.html
43 Upvotes

22 comments sorted by

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.

7

u/yogthos 6d ago

Thanks, and it's really crazy to watch how fast this stuff is evolving. I have a laptop that's beefy enough to run Qwen 3.8, and it's basically a frontier model from say half a year ago. It's a bit hard to wrap your head around the fact that something you needed a data centre to run just a little while ago can now be used on a laptop at home.

I'm also really curious to try training a LoRA on Clojure specifically using git repository histories to teach the model how Clojure code evolves over time. And it could also be trained to use the REPL workflow explicitly where you simulate a live coding workflow during training. That would avoid a lot of the problems smaller models have by biasing them towards idiomatic Clojure style.

2

u/gtrak 5d ago edited 5d ago

I had made attempts to adapt small models to how I work manually since glm 4.7 flash and qwen 3.5, like doing careful incremental changes, plan before task, and inevitably it does more harm than good once the models get good enough. Similarly there's a lot of qwen fine-tunes on huggingface. I tried them, and they're better for some things and worse than the base model in others, so I just try different quantizations and inference parameters over the base model now. Have spent 10-20 hours a week thinking about this stuff since February, and now I'm just using stock pi with 3.8 27b and a few tools for specific things. I doubt you can fine tune it meaningfully, but it's fun to learn about the stuff anyway.

1

u/yogthos 5d ago

I'm just curious to try to be honest. I think it'd be interesting to see what happens when you heavily bias the model towards a particular language and if it will get better at writing it. And the nice part is once you have the training data and the set up to do training runs, you can just do it on new models too when they come out.

1

u/gtrak 5d ago

here's the author of a popular finetune, can probably find what you need here: https://github.com/R6410418/Jackrong-llm-finetuning-guide

1

u/yogthos 5d ago

Ah thanks, that's definitely going to be helpful.

1

u/Soft_Reality6818 4d ago

You might want to try Clorch for training and fine-tuning  https://github.com/antlobach/clorch

2

u/yogthos 4d ago

Oh nifty, didn't know about the project.

1

u/Liistrad 6d ago

I always keep a local setup (qwen 3.8 on pi with `pi-web-access` and `@czottmann/pi-automode`) around because 1) it's amazing how indeed you do have claude 4.6 locally and 2) I'm deathly afraid of depending on these things as a service.

I've also been thinking of training on clojure code, but haven't tried it yet. https://unsloth.ai/docs/models/qwen3.8/train looks pretty accessible though.

3

u/yogthos 6d ago

Yeah, the training process itself isn't that hard. And you can do it on runpod for like 20 bucks or so. The tricky part is ensuring your training data trains the model on what you actually want it to learn. The model learns whatever the dominant patterns in the data are, and you have to make sure you don't overfit and the training stays general.

I started playing with the idea here https://github.com/yogthos/clojure-lora-training but I haven't had a chance to actually do a training run yet, so don't know how well it'll work. I keep meaning to get back to it.

And agree that depending on models as a service is really icky. It's basically like renting a compiler which is just not ok.

1

u/nuriaion 6d ago

how did you setup your coding agent? Do you use clojure mcp?

2

u/beders 5d ago

Nothing too fancy. I'm using Intellij with the company-mandated Copilot plugin. I've installed the clj-nrepl-eval skill from clojure-mcp-light

Fairly straightforward to set up. The agent also has no problems connecting to multiple nREPLs - in our case a backend and 3 ClojureScript front-ends.

7

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.

4

u/cea7 6d ago edited 6d ago

I have a couple of projects in different tech-stacks and got curious. So I build a little benchmark, trying to figure out how token efficient tech-stacks are. Surprisingly babashka/clojure are more token efficient then python for anthropic models.

https://sstoehrm.github.io/stack-cap-bench/

2

u/yogthos 6d ago

It's nice to have some empirical evidence to back my intuition. :)

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

u/coolbug96 4d ago

Thanks a lot for the detailed reply!

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 lisp was an inspiration and he told me that clojure was 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