rewrite-clj

Matthew Davidson 2023-01-30T11:19:09.129039Z

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

borkdude 2023-01-30T11:24:55.554449Z

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

borkdude 2023-01-30T11:25:30.629819Z

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

Matthew Davidson 2023-01-30T11:29:53.714049Z

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

borkdude 2023-01-30T11:30:36.541169Z

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

borkdude 2023-01-30T11:30:53.309859Z

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

borkdude 2023-01-30T11:32:23.303259Z

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

borkdude 2023-01-30T11:33:49.192909Z

Ah I think I know why equality doesn't work

borkdude 2023-01-30T11:34:13.767089Z

The constructor inserts a function in one of the fields

borkdude 2023-01-30T11:34:33.044469Z

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

borkdude 2023-01-30T11:35:30.137639Z

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

borkdude 2023-01-30T11:35:50.594769Z

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

borkdude 2023-01-30T11:37:50.374019Z

That would be a quick way to solve it

borkdude 2023-01-30T11:45:56.546819Z

I'm already working on a fix

πŸ‘ 1
borkdude 2023-01-30T11:48:54.055069Z

https://github.com/clj-commons/rewrite-clj/pull/213

lread 2023-01-30T14:43:33.679479Z

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

lread 2023-01-30T16:03:19.306229Z

Merged!

borkdude 2023-01-30T16:19:40.214999Z

@lee Maybe we can do a release some time

lread 2023-01-30T16:30:55.383069Z

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

πŸŽ‰ 1
lread 2023-01-30T18:00:45.790199Z

Done!

πŸŽ‰ 2
Matthew Davidson 2023-01-30T11:20:19.908209Z

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