Fork me on GitHub
#rewrite-clj
<
2023-01-30
>
Matthew Davidson (kingmob)11:01:09

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

borkdude11:01:55

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

borkdude11:01:30

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

Matthew Davidson (kingmob)11:01:53

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

borkdude11:01:36

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

borkdude11:01:53

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

borkdude11:01:23

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

borkdude11:01:49

Ah I think I know why equality doesn't work

borkdude11:01:13

The constructor inserts a function in one of the fields

borkdude11:01:33

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

borkdude11:01:30

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

borkdude11:01:50

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

borkdude11:01:50

That would be a quick way to solve it

borkdude11:01:56

I'm already working on a fix

👍 2
lread14:01:33

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

borkdude16:01:40

@UE21H2HHD Maybe we can do a release some time

lread16:01:55

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

🎉 2
lread18:01:45

Done!

🎉 4
Matthew Davidson (kingmob)11:01:19

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