r/Clojure • • 1d ago

What Makes a Programming Language AI-First? My Case for Clojure

https://adamtornhill.substack.com/p/what-makes-a-programming-language
45 Upvotes

16 comments sorted by

17

u/Hostilian 1d ago • This

I threw Claude at writing some Jank code a few weeks ago, mostly as an experiment, and it generated very tasteful Clojure code. Much moreso than the Typescript it poops out at my day job, which tends to be—for lack of a better concise descriptor—flabby. I was so impressed that when I finally get around to trying to build a couple of planned side-projects, I'll probably reach for some Clojure dialect first.

8

u/Due-Result7928 1d ago

There is a very simple reason. Code quality is better with Clojure and AI uses what is available not inventing the wheel.

3

u/Hostilian 1d ago

That is my hypothesis as well: it is using a very clean training set vs Typescript.

I also assume that’s why “rewrite this in Rust. Make no mistakes” actually sometimes works.

10

u/beders 1d ago

We are making the same observations over here in fintech land (deeply embedded in large regional bank):
Frontier language models spit out great Clojure code - adapting their code style to already existing pre-AI code - and have no trouble using multiple REPLs at the same time.

Changes across the stack (which includes Cljs) are created, run and tested quickly.
Even Copilot on Auto mode is doing a reasonably good job (Auto mode is cheaper).

I am wondering what people are adopting for multi-player mode: a mix of people and agents working on a larger feature/epic.

7

u/jaspingrobus 1d ago

I really enjoyed reading the post, but it left me wondering what would happen if the author tried something like Gleam/Elixir or even F#. I imagine he would still very much miss the interactive verification with REPL, but compile guarantess for static types feels like a pro for working with agents.

2

u/source-drifter 1d ago

about a month ago, i tried to integrate babaska into my harness flow. i was sick of getting code errors when bots build tooling and what not. it went horribly. bots are terrible at counting parens it seems. i'm working local models with consumer hardware, though. just to be clear.

7

u/ForeverFactor 1d ago

I had paren counting issues frequently with agents but after adding clojure-mcp to my agents tool box the problems went away. No guarantee it will help your scenario. I haven't dug into exactly why but I think the agents started evaluating code and getting feedback quicker.

1

u/source-drifter 1d ago

well, what i did was to run a repl server and asked model to use it to write and test the code before turning them into babashka scripts. i dont know what mcp adds to that but that didnt help.

1

u/nephrenka 1d ago

That sounds pretty much like my initial experience with generating Clojure back in the GPT-3.5 days. Completely unusable. But LLMs have come a long way since then, and I virtually never see a syntactic error or other unpleasant surprises with frontier models. (My current preference is Opus 5.5).

2

u/jalopy-letup-hum 1d ago

Which models, quantization, harness, context size were you using? I get parens errors here and there with qwen 3.8 27B UD Q6KL 128k cxt (to give one example) especially with larger contexts filled up. With the pi harness I make sure a fast syntax check runs on every file modification. If parens are unbalanced the tool call fails with a helpful error message and rejects the change. I noticed that small local models frequently fail to fix lisp syntax and they start to go crazy editing unrelated code. Better to discard the change and try again.

3

u/source-drifter 1d ago

opencode, pi as harness. qwen flash on strata or 27b on llamacpp. i only got 24vram so i'm on lower quants.

5

u/red_hare 1d ago edited 1d ago

In retrospect, clojure would be a great agent language with the advent of "code mode" style tool calling (call code that calls tools rather than tools directly). Plus modern async handling.

2

u/yogthos 1d ago

Incidentally, I've gone with code mode approach in samizdat and it seems to work pretty well.

5

u/yogthos 1d ago

Agree, and I'd argue the same features that help humans also help agents. For example, immutability as the default helps minimize the scope an LLM needs to track in order to make a change correctly. Clojure being concise and expressive also helps reduce the amount of tokens the LLM needs to use which directly shrinks the context. And nREPL driven workflow provides the agent with a fast feedback loop where it can try things and iterate step by step.

I also found it's helpful to add tooling for the LLM. I ended up making a jolt-metrics tool which tracks things like cyclomatic complexity, duplication, Halstead metrics, and so on, which helps with maintaining code quality, and spot a lot of questionable patterns. I also made jolt-lsp which provides a lot of tools similar to clj-kondo and an MCP, and a jolt-nrepl-mcp for the agent to drive the app using nREPL. And then I tied all of that together with jolt-skills that guide the agent towards using things as intended.

I find the results are better than I expected. I can now reliably build a working app like this in a day or so, something that would've taken months of work before.

1

u/ertucetin 5h ago

I wish Anthropic and OpenAI would make a statement like, “We recommend using Lisps like Clojure for coding.” That could really boost the language’s visibility. :)