If two objects are identical (actually point to the same slot in memory), they can immediately be determined to be equal.
There are also some ways to quickly determine that things are definitely not equal. For example, two vectors with different sizes are not equal. As you've pointed out, if the hashes of two objects are different, one can potentially quickly conclude that the two objects are not equal, but the Clojure code currently is somewhat inconsistent about applying this test. I think this inconsistency is because cached hashes are a relatively recent addition, and it hasn't quite percolated through to all the places that could take advantage of this. If the objects are different and the hashes are the same, you still have to compare the entire structures to be certain they are equal. On Thu, Nov 28, 2013 at 2:03 PM, Andy Smith <the4thamig...@googlemail.com>wrote: > Hi, > > I heard Rich Hickey talking about how identity in clojure is synonymous > with value-based tests of equality. To make this efficient he describes > that objects store cached hashes that are used to speed up these tests of > equality, so clojure isnt comparing every data member of a complex data > structure. However, how does this actually work since a comparison of > hashes doesn't guarantee that two objects are equal. How does clojure > handle the case where two hashes are the same for two distinctly different > values. > > Andy > > -- > -- > 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 > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > -- -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.