Fork me on GitHub
#rewrite-clj
<
2023-12-23
>
Gerome06:12:02

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?

borkdude08:12:33

Internal implementation detail, not part of the public API.

borkdude08:12:31

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

Gerome08:12:53

> 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.

borkdude09:12:06

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

borkdude09:12:31

parsing that source code back will give you the AST back

borkdude09:12:38

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

👍 1
Gerome09:12:43

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.

borkdude09:12:49

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

borkdude09:12:59

what kinds of queries will you be doing on it?

Gerome09:12:14

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

borkdude09:12:10

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