Fork me on GitHub
#rewrite-clj
<
2022-06-03
>
Dumch11:06:33

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.

Dumch11:06:56

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

borkdude11:06:16

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?

Dumch11:06:08

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.

Dumch11:06:59

In some cases this generated code is far too dirty 🙂

borkdude11:06:30

Maybe you can already fix in in the generator?

Dumch11:06:25

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

Dumch11:06:27

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

🎉 1
Dumch11:06:47

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