Structures
Learn about Clojure's many data structures and how to effectively use them.
Properties
Clojure has a huge set of data structures that have some properties in common:
They are immutable, readable, and persistent, so they always preserve the previous version of themselves when they’re modified.
They allow value equality semantics in any comparison of equals, so we can use
=
to validate them.They provide hash values, which are numeric values that uniquely identify data, in a good way.
Furthermore, the abundance of data structures has an impact on the JVM due to its support for all types found in Java.
The nil
value
In Clojure, nil
is a possible value of any data type. It’s similar to null
used in other programming languages, so it’s a representation of an empty value. Conditionals in Clojure are based around nil
and false
, similar to other languages; nil
equates to falsity in logic. Moreover, by default, if a function in Clojure hasn’t received a return type, nil
is always returned.
Get hands-on with 1200+ tech skills courses.