You're viewing version 1.2.0 of =. The latest stable version of Clojure Core is 1.3.0.
1.2.0 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:653 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/=: defn first next
Used in 180 other vars (expand)
not= ns-publics with-open dotimes ns-interns loop distinct? isa? when-first *clojure-version* ns when-let case if-let partition defmulti list-model *core-java-api* skip-whitespace skip-if-eol repl write pprint fresh-line print-trace-element triml escape blank? trim-newline content-handler next end? root encode make-map cond-let get-cell get-values cell get-value merge-relations any-match? ensure-relation compute-sip add-tuple is-query-var? is-var? project-literal negated? positive? negated-literal with-handler raise* in-case-test case ns-decl? comment? *core-java-api* start-handling-break = recursive-component? stratification-list stream open-url-in-swing maybe-atomize operation attribute-info write once monad-transformer column-writer end-block indent pretty-writer prefix-count rtrim ltrim start-block pprint fresh-line pprint-reader-macro normalize-cond normal-box-muller includes? includes? transaction* docodepoints dochars defst docodepoints dochars do-swing* tag= text= attr= wrap-file minus div sample-gamma sample-normal mmult truncated-variance add-pointer $group-by to-vect query-to-pred dataset? infix-to-prefix text-width background som-batch-train sample sample-uniform sample-t sample-exp sample-poisson sample-permutations sample-beta hamming-distance pairs concordant? sample-neg-binomial sample-binomial sample-chisq deriv* property-descriptor eval-in-project compile get-arglists form-for-testing-namespaces once =>-assertion? rewrite-=> should-body debug-repl match-fn dr-read caught union intersection tag= at transform attr= id= comment? document? xref symbol-name-parts one-of? thread-for-evaluation local-bindings largest-common-prefix dispatch-event with-package-tracking expand-wildcard split-compound-prefix-match? inspector-next exactly in-any-order exactly in-any-order exactly in-any-order ssh-sftp-cmd has-identity? memfn-varargs partial-namespace-matcher new-sandbox new-sandbox-compiler namespace-matcher class-matcher expand-and-quote dot-replace function-matcher fn-seq group-container-args changed-path combinations once

Comments top

1 comment(s) for =.

There is a difference between "=" and "==". For primitives you definitely want to use "==" as "=" will result in a cast to the wrapped types for it's arguments.

This may not be the case come Clojure 1.3 (see [1])

[1] http://github.com/clojure/clojure/commit/df8c65a286e90e93972bb69392bc106128427dde

Log in to add a comment.