• (diff a b)
Recursively compares a and b, returning a tuple of
[things-only-in-a things-only-in-b things-in-both].
Comparison rules:

* For equal a and b, return [nil nil a].
* Maps are subdiffed where keys match and values differ.
* Sets are never subdiffed.
* All sequential things are treated as associative collections
by their indexes, with results returned as vectors.
* Everything else (including strings!) is treated as
an atom and compared for equality.

1 Example top

  • (use 'clojure.data)
    (def uno {:same "same", :different "one"})
    (def dos {:same "same", :different "two", :onlyhere "whatever"})
    (diff uno dos)
    => ({:different "one"} {:onlyhere "whatever", :different "two"} {:same "same"})
    ;;  {different in uno} {     different or unique in dos       } {same in both}
    (diff {:a 1} {:a 1 :b 2})
    => (nil {:b 2} {:a 1})
    ;; the first contains nothing unique, but only the second contains :b
    ;; and both contain :a
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/data.clj:104 top

(defn diff
  "Recursively compares a and b, returning a tuple of
  [things-only-in-a things-only-in-b things-in-both].
  Comparison rules:

  * For equal a and b, return [nil nil a].
  * Maps are subdiffed where keys match and values differ.
  * Sets are never subdiffed.
  * All sequential things are treated as associative collections
    by their indexes, with results returned as vectors.
  * Everything else (including strings!) is treated as
    an atom and compared for equality."
  {:added "1.3"}
  [a b]
  (if (= a b)
    [nil nil a]
    (if (= (equality-partition a) (equality-partition b))
      (diff-similar a b)
      (atom-diff a b))))
Vars in clojure.data/diff:
Used in 0 other vars

Comments top

No comments for diff. Log in to add a comment.