On Sun, Aug 30, 2009 at 12:32 PM, CuppoJava <patrickli_2...@hotmail.com>wrote:
> > Your examples are very good I think. It always helps to have a > straight-forward conversion from one language to another for > beginners. They will eventually pick up idioms and methodology by > playing around. > > One comparison that bothers me though is this: > > (not= (new Exception) (new Exception)) > Again, Clojure works just like Python. Two distinct objects are not > equal. > > This is not strictly true. (new Exception) is not equal to (new > Exception) because equals() is defined as being an identity > comparison. Other classes define equals() differently. > > eg. (not= (new Integer 2) (new Integer 2)) > There's an identical? predicate. It will return false for the above. Interestingly, it will return true for two of Integer/valueOf 2, and likewise for any other integer between -128 and 127 inclusive, otherwise false. Integer values that fit in a signed byte are apparently cached. But "new" must always generate a new object, so (identical? (new ...) (new ...)) always returns false no matter what replaces each "...". --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---