This is interesting to me. I've thought for a while that I wanted to
be notified of changes to a collection, such as in a Ref's watcher.
But I couldn't think of a good way to go about it, since the new value
of a Ref may have no relationship at all with the old value.
But your question suggests a different approach. Efficiently
obtaining a "diff" that describes the differences between two
collections would suffice for most of my use cases.o
The collections don't support this now, as far as I know, but off the
top of my head it seems like it would be possible for any
collection instance to walk itself at the same time as another
instance of the exact same type, following only nodes that are not
identical references. This wouldn't work to compare an array-map with
a hash-map, for example, but in an ideal case of two hash-maps with a
single changed entry, it seems like it could be very efficient.
Perhaps O(n) where n is the number of changed leaf nodes?
I'm not sure what the resulting "diff" would look like. It would be
nice if it were simple another hash-map: (diff a b) would return a map
c such that (merge a c) would produce a value equal to b again. But
for course this can't be as 'merge' never removes an entry. An option
that would work (but doesn't strike me as terribly elegant) would be
for (diff a b) to return [c d], such that:
(= b (merge (apply dissoc a c) d))
--Chouser
my programming language enchilada (www.enchiladacode.nl)