Fork me on GitHub

from time to time I dream of a declarative refactoring engine, e.g. for every second argument given to foo , wrap it in a hashmap with key :bar. is it an idea you've entertained much? I'd imagine that is much much easier said than done 😇


Hi @vemv, no, that has not come to my mind. But there are more things in heaven and earth, vemv, than are dreamt of my wee brain! So you’d have some declarative recipe that turns:

(foo 1 2 3 4 5 6)
That would produce this?:
(for 1 {:bar 2} 3 {:bar 4} 5 {:bar 6})
Without thinking about it too much, I’d probably lean toward simply coding up something in Clojure to do the transform instead of creating some sort of DSL.


I would prefer coding it over a DSL myself.


Note that you can use other tools (like clj-kondo) to detect the positions of all the calls of foo, and then use fairly thin rewrite-clj code to transform those calls


The problem with a DSL is usually that it covers 80% of what you want, but then you leave it for coding anyway


> I would prefer coding it over a DSL myself. I have mixed feelings about it. Probably a fully generalized DSL would be overly dense, but I sense that telling people to code rewrite-clj script for any possible refactoring idea would not make people very enthusiatic. Maybe the middle ground would be implementing different 'intents' that a user may want. 1 intent == 1 defn, defns might compose There's more to writing a rewrite-clj 'script' anyway i.e. traversing a codebase, filtering out false positives, etc. So I sense there's a place for a 'framework'


A lot of what is in clojure-lsp may already worth getting out into a library


and libraries I would much prefer over a framework, but this is often just a matter of framing :)