> However, it is a Java *contract* [1] that > (.equals x y) ==> (== (.hashCode x) (.hashCode y)) and currently > Clojure data structures violate this contract:
> [1]http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html#hashCode() And, while on this subject, it's also worth pointing out that this contract is also violated by Clojure data structures if you mutate things behind their backs: user> (let [xs (take 2 (repeatedly #(make-array Object 1))) init-seqs (map seq xs)] (doseq [x init-seqs] (hash x)) (aset (first xs) 0 10) (let [all-seqs (cons (seq (first xs)) init-seqs)] (doseq [s all-seqs] (print "\n" (.hashCode s)) (doseq [t all-seqs] (print "\t" (.equals s t)))))) -1640531517 true true false -1640531527 true true false -1640531527 false false true As an fun fact, commenting out the (on the surface, purely functional) doseq line actually eliminates the problem, since hash values are presumably computed on first request and then cached. I understand why this is done and don't see it as much of a problem, just something that users should be aware of. Perhaps one of the pages on the website (Java interop / data structures?) should mention this? Cheers, Jason --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---