rewrite-clj

Gerome 2023-12-23T06:13:02.948149Z

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?

borkdude 2023-12-23T08:13:33.730379Z

Internal implementation detail, not part of the public API.

borkdude 2023-12-23T08:17:31.615169Z

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

Gerome 2023-12-23T08:30:53.761119Z

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

borkdude 2023-12-23T09:05:06.720149Z

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

borkdude 2023-12-23T09:05:31.118999Z

parsing that source code back will give you the AST back

borkdude 2023-12-23T09:07:38.006399Z

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

👍 1
Gerome 2023-12-23T09:07:43.828179Z

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.

Gerome 2023-12-23T09:08:09.140179Z

Alright

borkdude 2023-12-23T09:08:49.301309Z

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

borkdude 2023-12-23T09:10:59.335269Z

what kinds of queries will you be doing on it?

Gerome 2023-12-23T09:44:14.291799Z

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

borkdude 2023-12-23T09:45:10.581399Z

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