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))
trueAh 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))
trueor 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
Thanks so much, I'll take a peek soon!
Merged!
@lee Maybe we can do a release some time
Yeah, why not? I'll cut one after I do some snow shovelling.
Done!
More generally, I'm having trouble understanding when I should be using the zip API, the node API, or manipulating clojure forms/sexprs.
https://clojurians.slack.com/archives/C06MAR553/p1675101462159299