If Clojure's primary objective were Java interop, I might agree with you. However, it's not, and it's bizarre to see someone argue that this is not broken:
user=> (.equals (Integer. -1) (Long. -1)) false Sure, not broken according to the Java object model and its equality semantics, but damn well broken if your standard is something other than what was canonized in java.lang.Object 20 years ago. 1 == 1 all the time — or, it should — regardless of the containers such integers incidentally find themselves within. Thus, Clojure's notion of equivalence, which leads to pleasantly consistent behaviour, e.g. (== (Integer. 1) 1 1N). Which, of course, doesn't preclude one using .equals if you truly want Java math semantics instead of = or == (neither of which have ever been advertised as adhering to the hashcode/.equals contract, at least since Clojure 1.0 IIRC). If there are some common rough spots in the interop for certain use cases, perhaps those can be smoothed out with a library, maybe contributed by someone that acutely feels that pain. - Chas On Oct 22, 2011, at 7:13 AM, Paul Stadig wrote: > On Wednesday, October 19, 2011 10:38:56 AM UTC-4, stuart....@gmail.com wrote: > >Integers and longs are going to be painful no matter what because they are > >broken in Java, e.g. > > It is incorrect to say that "Integers and longs...are broken in Java." > > user=> (.hashCode (Integer. -1)) > -1 > user=> (.hashCode (Long. -1)) > 0 > user=> (.equals (Integer. -1) (Long. -1)) > false > > This is consistent with the contract for hashCode. Java would be broken only > if equals returned true, but the hashCodes were different. If anything > Clojure was (and in fact still is) broken, since Clojure makes Long and > Integers in the same range equal, but does not make their hashCodes equal: > > user=> (hash (Integer. -1)) > -1 > user=> (hash (Long. -1)) > 0 > user=> (= (Integer. -1) (Long. -1)) > true > > Henceforth referred to as "the hashCode problem". -- 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