May 2018
Beginner to intermediate
290 pages
6h 43m
English
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 ...
Read now
Unlock full access