On REPL, if I define
(def fits (map vector (take 10 (iterate inc 0))))
and then call
(== [2] (nth fits 2))
I get false.
But
(= [2] (nth fits 2))
returns true.
Is this expected ? I tried (class [2]) and (class (nth fits 2) and both return Persistent Vector.
==is for comparing numbers. If either of its arguments is not a number, it will always return false:As you can see by saying
(clojure.contrib.repl-utils/source ==)at the REPL (withrepl-utilsrequire‘d, of course),==calls theequivmethod ofclojure.lang.Numbers. The relevant bit ofclojure/lang/Numbers.java(from the latest or close-to-latest commit on GitHub):Use
=for equality comparisons of things which may not be numbers. When you are in fact dealing with numbers,==ought to be somewhat faster.