Has anyone else noticed that AI code generators love overusing atoms in Clojure? I wonder where that is coming from, is there a massive codebase somewhere overusing atoms that it's learning from? I would expect this pattern from a junior engineer who is used to writing in e.g., Python or Java and hasn't grasped functional or declarative programming style, but not from an AI which I expect to mostly regurgitate codebases it has ingested.
what prompt are you using? i'll try and find the link of the one i use the thing i run into most frequently/annoyingly is hallucinations of functions that either don't exist, or don't work in the way it claims to
(i use this, minus the re-frame stuff https://github.com/ovistoica/emacs/blob/main/prompts/clojure-expert.md)
I just ask it a simple question, like I have x function but it's bugging on this input, how do I fix. Or "set up a test for this function"
That's a great resource, thanks! Do you feed it into ChatGPT or set it up in a code editor like Windsurf?
i dont use it super frequently (because often im looking for the things that its deciding to hallucinate), but i usually feed it into whatever model on Kagi Assistant, i haven't reached the hooked-into-editor point yet :^)
I haven’t noticed that, but I don’t use them much.
Is it using the atom to log/save some temporary data for debugging during REPL development? That can be a legitimate use, I use atoms to log/save stuff to observe what is happening.
It mostly uses atoms like a procedural programmer uses variables, as a place to store and mutate state during a computation. Again just like a junior programmer who hasn't been trained on persistent data structure and functional-declarative style. That's the weird part for me
It's the obvious way to map some mutable algorithms over to clojure, right? I used to do that before I could recognize what mapped to functional idioms iirc
I do think you can prompt it towards a more functional mindset. Explicitly telling it to try to avoid using local atoms might help
That being said, even naively mapping to some local atoms based solution is still going to have safer concurrency semantics than a more idiomatic port
Can't say I've noticed an abundance of atoms with any of the models I've used (via Cursor), but @petrus's https://github.com/theronic/clojure-prompts may help
I recently rewrote some python code in clj, using Cursor and noticed it was using atoms and had to several times suggest using either a reduce or a loop recur. Once suggested it did it correctly
Yea +1 on guiding it to use reduce/loop, it's hard one-shotting it without a good system prompt though