In the Wild

Our old friend the built-in = function is a great example of the function-related goodies we’ve been looking at in this chapter:

 ;; Code edited a bit for clarity.
 
 (​defn​ =
 "Equality. Returns true if x equals y, false if not. Same as
  Java x.equals(y) except it also works for nil, and compares
  numbers and collections in a type-independent manner.
  Clojure's immutable data structures define equals()
  (and thus =) as a value, not an identity, comparison."
  ([x] true)
  ([x y] (clojure.lang.Util/equiv x y))
  ([x y & more]
  (​if​ (clojure.lang.Util/equiv x y)
  (​if​ (next more)
  (recur y (first more) (next more))
  (clojure.lang.Util/equiv y (first more)))
  false)))

The = function takes any number of arguments ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.