rewrite-clj 2023-01-30

Is there a notion of equality for nodes? The zip API was feeling restrictive, so I was exploring the node API, but I can't create a target node and search for a node equal to it. E.g.:

(= (n/list-node (n/token-node 'f)) (n/list-node (n/token-node 'f)))
=> false

@kingmob I'm using the node API a lot myself too. In fact, clj-kondo exclusively uses it.

For comparing I sometimes compare the stringified results in clj-kondo (which seems a bit of a workaround)

Thx, that’s interesting. Why is kondo mostly using the node API?

Since nodes are just records which should already implement equality, I'm surprised that the above doesn't return true

I tested the zipper API but manually working with nodes performed way better

user=> (= (n/token-node 'f) (n/token-node 'f))
true

Ah I think I know why equality doesn't work

The constructor inserts a function in one of the fields

I think we could fix this by overriding equals, feel free to post an issue

user=> (= (dissoc (n/list-node []) :seq-fn) (dissoc (n/list-node []) :seq-fn))
true

or we could fix this by re-using the seq-fn for every instance

That would be a quick way to solve it

I'm already working on a fix

πŸ‘ 1

Thanks so much, I'll take a peek soon!

@lee Maybe we can do a release some time

Yeah, why not? I'll cut one after I do some snow shovelling.

πŸŽ‰ 1

Done!

πŸŽ‰ 2

More generally, I'm having trouble understanding when I should be using the zip API, the node API, or manipulating clojure forms/sexprs.