liveBook · Manning

Compatibility group

As explained in Clojure: The Essential Reference

A compatibility group is a category of Clojure types whose values can be compared by common equivalence rules.

A compatibility group identifies Clojure types that `=` can compare under common rules. Compatible values need not have the same concrete type. section 6.1

The comparison rule depends on the group:

  • List-like values—lists, vectors, queues, ranges, and lazy sequences—compare contents in order. section 6.1
  • Map-like values compare entries without regard to order; set-like values likewise compare members without regard to order. section 6.1
  • Integer types, including ratios, form one group; floats and doubles form another. Compatible noncontainers compare by value. section 6.1

Container type versus content

`(= '(1 2) [1 2])` returns `true`: the list and vector belong to the ordered list-like group. Reversing either collection’s contents makes the comparison false. section 6.1

Types outside these groups, such as strings, keywords, big-decimals, and plain Java types, compare only with their own type. Incompatible groups compare unequal. section 6.1

How Clojure: The Essential Reference covers it

How deep it goes
Defines the groups and their ordered, unordered, or value-based equality rules.
Examples
Illustrates equality with a list and vector containing the same ordered values.
What you can do after
Evaluate/understand whether `=` can treat differently typed values as equivalent.
How it connects
Connects compatibility groups to collection equality, numeric equality, and Java object semantics.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.