rewrite-clj

Dumch 2022-06-03T11:10:33.405969Z

Hey! Just to be sure I am not overcomplicating. I want to remove redundant nesting (+ (+ 1 2) 3) —> (+ 1 2 3) . And here is the code I came up with. Is it ok? I am asking because compared to simbols manipulations (another screean I've attached) it's too big and dificult to read.

Dumch 2022-06-03T11:11:56.570529Z

I first tried to do it with zip-api, but wasn't able to have a simple solution

borkdude 2022-06-03T11:20:16.678089Z

I think you should first ask yourself if the problem is worth solving. It is convenient but I think most users can handle this manually when they see it?

Dumch 2022-06-03T11:28:08.484639Z

I think that this kind of problems are routine that should be automated. I only didn't want to translate the code, that shouldn't be translated, like classes declaration, because it is not an idiomatic clojure and it's far from trivial to rewrite classes into proper clojure code.

Dumch 2022-06-03T11:32:59.422569Z

In some cases this generated code is far too dirty 🙂

borkdude 2022-06-03T11:35:08.845549Z

I see :)

borkdude 2022-06-03T11:35:30.193069Z

Maybe you can already fix in in the generator?

Dumch 2022-06-03T11:38:25.571899Z

may be it will be easier, I will take a look

Dumch 2022-06-03T11:52:27.269609Z

Thanks, I can use simple function like above (small screen) to convert AST from nesting form into flat one

🎉 1
Dumch 2022-06-03T11:52:47.360549Z

(defn flatten-same-node [[f & params]]
  (list* f (mapcat 
             #(if (and (sequential? %) (= (first %) f))
                (next (flatten-same-node %))
                [%])
             params)))