Clojure

structural diff

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: Release 1.3
  • Component/s: None
  • Labels:
    None
  • Approval:
    Ok

Description

I constantly find myself writing ad hoc code to compare bits of structure, either at the REPL or in tests. (Or even worse, trying to eyeball two long pprint outputs).

What I want instead is a diff function that compares two structures a and b, returning the parts only in a, parts only in b, and parts in both. Good solution for my needs should:

  • work with all kinds of collections (both Clojure and Java)
  • make simple choices about how to define a "difference"
  • need not worry too much about perf

Activity

Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - stu said: [file:dr3uxCZj4r36h-eJe5cbLr]
Hide
Assembla Importer added a comment -

stu said: Not attached to the namespace or fn names, nor to having this in Clojure as opposed to contrib. Just had to put it somewhere to solicit feedback.

Show
Assembla Importer added a comment - stu said: Not attached to the namespace or fn names, nor to having this in Clojure as opposed to contrib. Just had to put it somewhere to solicit feedback.
Hide
Assembla Importer added a comment -

laurentpetit said: Did you know about difform before starting this ? Looks like an interesting implementation :

http://github.com/GeorgeJahad/difform

Show
Assembla Importer added a comment - laurentpetit said: Did you know about difform before starting this ? Looks like an interesting implementation : http://github.com/GeorgeJahad/difform
Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - stu said: [file:dXJg-aZlyr35yieJe5cbCb]
Hide
Assembla Importer added a comment -

stu said: Hmm, difform is cool, but coming at the problem from a different direction. I think there is room for both.

Show
Assembla Importer added a comment - stu said: Hmm, difform is cool, but coming at the problem from a different direction. I think there is room for both.
Hide
Assembla Importer added a comment -

stu said: Second patch (using a multimethod) reads better I think.

Show
Assembla Importer added a comment - stu said: Second patch (using a multimethod) reads better I think.
Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - stu said: [file:bkIb2GZnOr363HeJe5cbLr]
Hide
Assembla Importer added a comment -

stu said: third patch (no mms) closes off potential for accidental comparison of unlikes

Show
Assembla Importer added a comment - stu said: third patch (no mms) closes off potential for accidental comparison of unlikes
Hide
Assembla Importer added a comment -

richhickey said: wow, reading patches of patches of patches is difficult

Show
Assembla Importer added a comment - richhickey said: wow, reading patches of patches of patches is difficult
Hide
Assembla Importer added a comment -

richhickey said: is the partitioning the same as for equality? If so it could be split out

the j.u.Collection ==> sequence case makes me wary - should it be j.u.List?

Show
Assembla Importer added a comment - richhickey said: is the partitioning the same as for equality? If so it could be split out the j.u.Collection ==> sequence case makes me wary - should it be j.u.List?
Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - stu said: [file:dhs7kcZ88r34I5eJe5cbCb]
Hide
Assembla Importer added a comment -

stu said: fourth patch (0448-data-diff.patch) is hopefully final:

  • replaces the others in a single clean patch.
  • partitions by List instead of Collection
  • renames the protocol and its fns to (better?) names
Show
Assembla Importer added a comment - stu said: fourth patch (0448-data-diff.patch) is hopefully final:
  • replaces the others in a single clean patch.
  • partitions by List instead of Collection
  • renames the protocol and its fns to (better?) names
Hide
Assembla Importer added a comment -

richhickey said: is the partitioning the same as for equality? If so it could be split out

Show
Assembla Importer added a comment - richhickey said: is the partitioning the same as for equality? If so it could be split out
Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - stu said: [file:b7-JX21Hur36gceJe5cbCb]
Hide
Assembla Importer added a comment -

stu said: 0448-data-diff-privatized.patch subsumes the others. Changes:

  • separated a protocol for EqualityPartition
  • marked things as private / implementation detail
  • used correct namespace clojure.data
  • added copyright notice
Show
Assembla Importer added a comment - stu said: 0448-data-diff-privatized.patch subsumes the others. Changes:
  • separated a protocol for EqualityPartition
  • marked things as private / implementation detail
  • used correct namespace clojure.data
  • added copyright notice
Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - stu said: [file:aoWwgo1Iqr36gceJe5cbCb]
Hide
Assembla Importer added a comment -

stu said: 0448-data-diff-nil-atom subsumes others, and puts nil into the :atom EqualityPartition

Show
Assembla Importer added a comment - stu said: 0448-data-diff-nil-atom subsumes others, and puts nil into the :atom EqualityPartition
Hide
Assembla Importer added a comment -

stu said: Updating tickets (#276, #280, #378, #437, #448)

Show
Assembla Importer added a comment - stu said: Updating tickets (#276, #280, #378, #437, #448)
Hide
Bryan Weber added a comment -

Does this diff include or ignore metadata? I frequently want to compare structures in unit tests, but I would actually like to take the metadata into account... It would be great to have as an option.

Show
Bryan Weber added a comment - Does this diff include or ignore metadata? I frequently want to compare structures in unit tests, but I would actually like to take the metadata into account... It would be great to have as an option.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: