summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2010-06-17 13:12:59 -0400
committerRich Hickey <richhickey@gmail.com>2010-06-17 13:12:59 -0400
commit8b849574ca1186c65124b43da8de6be6bace3f96 (patch)
treeaf097f9586e6c241d95721ce95a506778cef34c5
parent863decce5f38c8cde9882a0e172cbfe469f05743 (diff)
Change = to include type of boxed numbers (and collections thereof). Use == for inter-type numeric equivalence.
-rw-r--r--src/clj/clojure/core.clj16
-rw-r--r--src/jvm/clojure/lang/Util.java10
2 files changed, 14 insertions, 12 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index 795f23cb..2d130675 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -698,7 +698,7 @@
([x y] (clojure.lang.Util/identical x y)))
;equiv-based
-(defn =
+#_(defn =
"Equality. Returns true if x equals y, false if not. Same as
Java x.equals(y) except it also works for nil, and compares
numbers and collections in a type-independent manner. Clojure's immutable data
@@ -717,12 +717,11 @@
false)))
;equals-based
-#_(defn =
- "Equality. Returns true if x equals y, false if not. Same as
- Java x.equals(y) except it also works for nil, and compares
- numbers and collections in a type-independent manner. Clojure's immutable data
- structures define equals() (and thus =) as a value, not an identity,
- comparison."
+(defn =
+ "Equality. Returns true if x equals y, false if not. Same as Java
+ x.equals(y) except it also works for nil. Boxed numbers must have
+ same type. Clojure's immutable data structures define equals() (and
+ thus =) as a value, not an identity, comparison."
{:inline (fn [x y] `(. clojure.lang.Util equals ~x ~y))
:inline-arities #{2}
:added "1.0"}
@@ -953,7 +952,8 @@
false)))
(defn ==
- "Returns non-nil if nums all have the same value, otherwise false"
+ "Returns non-nil if nums all have the equivalent
+ value (type-independent), otherwise false"
{:inline (fn [x y] `(. clojure.lang.Numbers (equiv ~x ~y)))
:inline-arities #{2}
:added "1.0"}
diff --git a/src/jvm/clojure/lang/Util.java b/src/jvm/clojure/lang/Util.java
index eb94bfbc..a3306db6 100644
--- a/src/jvm/clojure/lang/Util.java
+++ b/src/jvm/clojure/lang/Util.java
@@ -35,6 +35,7 @@ static public boolean equals(Object k1, Object k2){
return k1 != null && k1.equals(k2);
}
+//*
static public boolean equals(long x, long y){
return x == y;
}
@@ -44,20 +45,21 @@ static public boolean equals(double x, double y){
}
static public boolean equals(long x, Object y){
- return equals((Object)x,y);
+ return equals(Numbers.num(x),y);
}
static public boolean equals(Object x, long y){
- return equals(x,(Object)y);
+ return equals(x,Numbers.num(y));
}
static public boolean equals(double x, Object y){
- return equals((Object)x,y);
+ return equals((Double)x,y);
}
static public boolean equals(Object x, double y){
- return equals(x,(Object)y);
+ return equals(x,(Double)y);
}
+//*/
static public boolean identical(Object k1, Object k2){
return k1 == k2;