rewrite-clj 2023-12-23

Hello everyone! I've been playing around with rewrite-clj a little and I noticed that nodes have a :seq-fn property but I haven't seen any documentation on what it is. What is it?

Internal implementation detail, not part of the public API.

What it is for, I’ve touched it a few times but have to look at the code to remember exactly… will do when I’m at the computer

> Internal implementation detail, not part of the public API. Hm, I understand. I’m trying to serialize the AST but in a way that allows reconstructing the source from the deserialized AST. This does not sound good though.

you can serialize the AST simply by calling str , this will give you back the source code

parsing that source code back will give you the AST back

I looked it up now: seq-fn is used to convert the node back into a s-expr

👍 1

Hm, I want to put the AST into a database and do queries on it. This would work well for very simple cases but if I‘m reading, say, an entire codebase, that won‘t help a lot.

Maybe for the database postwalk the AST and convert it to a more query-able structure?

what kinds of queries will you be doing on it?

For example, show me all the times a function was called or when this atom was mutated.

maybe the clj-kondo analysis will be more amenable to querying? https://github.com/clj-kondo/clj-kondo/blob/master/analysis/README.md