= 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/lang/Util.java
<https://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lang/Util.java%20>
[2] http://leepoint.net/notes-java/data/expressions/22compareobjects.html
[3]
https://github.com/richhickey/clojure/blob/master/src/jvm/clojure/lang/AFn.java

On Thu, May 5, 2011 at 3:04 PM, Dominikus <dominikus.herzb...@gmail.com>
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 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 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

Reply via email to