1.3.0 permalink Arrow_down_16x16
  • (= x)
  • (= x y)
  • (= x y & more)
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.

1 Example top

  • user=> (= 1)
    true
    user=> (= 1 1)
    true
    user=> (= 1 2)
    false
    user=> (= 1 1 1)
    true
    user=> (= 1 1 2)
    false
    user=> (= '(1 2) [1 2])
    true
    user=> (= nil nil)
    true
    
    ;; It should be noted that equality is not defined for Java arrays.
    ;; Instead you can convert them into sequences and compare them that way.
    ;; (= (seq array1) (seq array2))
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:718 top

(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."
  {:inline (fn [x y] `(. clojure.lang.Util equiv ~x ~y))
   :inline-arities #{2}
   :added "1.0"}
  ([x] true)
  ([x y] (clojure.lang.Util/equiv x y))
  ([x y & more]
   (if (= x y)
     (if (next more)
       (recur y (first more) (next more))
       (= y (first more)))
     false)))
Vars in clojure.core/=:
Used in 0 other vars

Comments top

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