It also seems that I have been linking to the wrong repo... :S https://github.com/clojure/clojure Should be the correct one.
On Thu, May 5, 2011 at 6:09 PM, Jonathan Fischer Friberg < [email protected]> wrote: > I'm also interested in that. > I think it has to do with how clojure.lang.Compiler [1] works (since that > is what eval uses), > but since it is quite big, I don't know exactly what parts are important. > > Jonathan > > [1] > https://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lang/Compiler.java > > On Thu, May 5, 2011 at 5:41 PM, Dominikus <[email protected]>wrote: > >> Thanks for the pointers to the implementation, Jonathan! >> >> Unfortunately, I couldnt' find out yet, which part of the source code >> in Clojure 1.3 is responsible for fixing the misbehavior in 1.2. The >> parts you point to haven't changed in 1.3. >> >> Cheers, >> >> Dominikus >> >> On May 5, 4:27 pm, Jonathan Fischer Friberg <[email protected]> >> wrote: >> > = uses the clojure.lang.Util/equiv to compare two "things". The source >> of >> > this function is: [1] >> > >> > static public boolean equiv(Object k1, Object k2){ >> > if(k1 == k2) >> > return true; >> > if(k1 != null) >> > { >> > if(k1 instanceof Number && k2 instanceof Number) >> > return Numbers.equiv(k1, k2); >> > else if(k1 instanceof IPersistentCollection && k2 >> instanceof >> > IPersistentCollection) >> > return ((IPersistentCollection)k1).equiv(k2); >> > return k1.equals(k2); >> > } >> > return false; >> > >> > } >> > >> > Which says: >> > if k1 and k2 is the same instance (has the same id), return true >> > if k1 and k2 are numbers, compare them as numbers >> > if k1 and k2 are collections, compare them as collections >> > otherwise, use the function "equals" of the k1 object. >> > >> > The equals function defines "intelligent" (proper) comparison of two >> > objects, and is defined by the programmer. If the equals function isn't >> > defined, it behaves like == [2] >> > The == function returns true if the "things" are of the same instance. >> > >> > I think functions in clojure are defined in [3], but I'm not entirely >> sure. >> > As you can see, equals isn't implemented, and thus = will only compare >> > instance (id), as you have noticed. >> > >> > Jonathan >> > >> > [1] >> https://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lan... >> > < >> https://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lan...> >> > [2] >> http://leepoint.net/notes-java/data/expressions/22compareobjects.html >> > [3] >> https://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lan... >> > >> > On Thu, May 5, 2011 at 3:04 PM, Dominikus <[email protected] >> > >> > wrote: >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > > My observation is best distilled with the following definition of a >> > > function in Clojure 1.2: >> > >> > > user=> (defn id [x] (list id x)) >> > > #'user/id >> > >> > > Interstingly, (id 7) and (eval (id 7)) result in different instances >> > > of function id as the number after the '@' char unveils: >> > >> > > user=> (id 7) >> > > (#<user$id user$id@53797795> 7) >> > > user=> (eval (id 7)) >> > > (#<user$id user$id@2de12f6d> 7) >> > >> > > Consequently, the following comparison leads to false: >> > >> > > user=> (= (id 7) (eval (id 7))) >> > > false >> > >> > > Why is the instance relevant to '='? What is the precise semantics of >> > > two values being equal in Clojure? >> > >> > > Dominikus >> > >> > > (Remark: In Scheme, the use of 'eqv?' returns also #f, but the less >> > > restrictive 'equal?' does not and returns #t.) >> > >> > > -- >> > > You received this message because you are subscribed to the Google >> > > Groups "Clojure" group. >> > > To post to this group, send email to [email protected] >> > > Note that posts from new members are moderated - please be patient >> with >> > your first post. >> > > To unsubscribe from this group, send email to >> > > [email protected] >> > > 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 post to this group, send email to [email protected] >> Note that posts from new members are moderated - please be patient with >> your first post. >> To unsubscribe from this group, send email to >> [email protected] >> 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 post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en
