Mamun <mamuni...@gmail.com> writes:

Hi Mamun,

> When I run the following code, I got false for (identical? 128 128).
> What is the different between = and identical?

= tests for equality (Object.equals() in Java) while identical? test for
the object identities being the same (== in Java).  128 is a
java.lang.Long, and there's nothing preventing that are multiple
instances (that are not identical) with equal value 128.  (However, the
JVM does some sort of pooling.  It seems there's exactly one Long for
any long value in the range [-128...127], but you shouldn't rely on
that.  Even then, you could do

  => (identical? 0 (Long. 0))
  false

(although you should use (Long/valueOf 0) instead of creating a new
object forcefully).

So in general, you mostly want =.  If you know you're comparing numbers,
then use ==.  If you really want to check for the object identity, then
use identical?.

Bye,
Tassilo

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to