summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2010-06-17 10:01:10 -0400
committerRich Hickey <richhickey@gmail.com>2010-06-17 10:01:10 -0400
commite526bb845d76dd920df335dedd796b8f44ab4b4e (patch)
tree714de3abc2f9a00a7ada66a5b496a1d8bb591db6 /src
parenta1a25da6b717af52cbd4e5c5e87de921ec8478eb (diff)
tighten up numeric comparisons
Diffstat (limited to 'src')
-rw-r--r--src/clj/clojure/core.clj26
-rw-r--r--src/clj/clojure/gvec.clj2
-rw-r--r--src/clj/clojure/pprint/cl_format.clj6
3 files changed, 27 insertions, 7 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index 6e426ae9..795f23cb 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -697,6 +697,7 @@
:added "1.0"}
([x y] (clojure.lang.Util/identical x y)))
+;equiv-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
@@ -715,6 +716,25 @@
(= y (first more)))
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."
+ {:inline (fn [x y] `(. clojure.lang.Util equals ~x ~y))
+ :inline-arities #{2}
+ :added "1.0"}
+ ([x] true)
+ ([x y] (clojure.lang.Util/equals x y))
+ ([x y & more]
+ (if (= x y)
+ (if (next more)
+ (recur y (first more) (next more))
+ (= y (first more)))
+ false)))
+
(defn not=
"Same as (not (= obj1 obj2))"
{:tag Boolean
@@ -2239,8 +2259,8 @@
[bindings & body]
(let [i (first bindings)
n (second bindings)]
- `(let [n# ~n]
- (loop [~i (int 0)]
+ `(let [n# (clojure.lang.RT/longCast ~n)]
+ (loop [~i 0]
(when (< ~i n#)
~@body
(recur (unchecked-inc-long ~i)))))))
@@ -2716,7 +2736,7 @@
(= 2 (count bindings)) "exactly 2 forms in binding vector")
(let [i (first bindings)
n (second bindings)]
- `(let [n# ~n]
+ `(let [n# (long ~n)]
(loop [~i 0]
(when (< ~i n#)
~@body
diff --git a/src/clj/clojure/gvec.clj b/src/clj/clojure/gvec.clj
index bfebb2ea..1b3443a5 100644
--- a/src/clj/clojure/gvec.clj
+++ b/src/clj/clojure/gvec.clj
@@ -192,7 +192,7 @@
(= (.nth this i) (nth o i)) (recur (inc i))
:else false)))
(or (instance? clojure.lang.Sequential o) (instance? java.util.List o))
- (= (seq this) (seq o))
+ (clojure.lang.Util/equiv (seq this) (seq o))
:else false))
clojure.lang.IPersistentStack
diff --git a/src/clj/clojure/pprint/cl_format.clj b/src/clj/clojure/pprint/cl_format.clj
index f04aa552..c2189d0c 100644
--- a/src/clj/clojure/pprint/cl_format.clj
+++ b/src/clj/clojure/pprint/cl_format.clj
@@ -425,9 +425,9 @@ Note this should only be used for the last one in the sequence"
not-teens (or (< 11 low-two-digits) (> 19 low-two-digits))
low-digit (rem low-two-digits 10)]
(print (cond
- (and (= low-digit 1) not-teens) "st"
- (and (= low-digit 2) not-teens) "nd"
- (and (= low-digit 3) not-teens) "rd"
+ (and (== low-digit 1) not-teens) "st"
+ (and (== low-digit 2) not-teens) "nd"
+ (and (== low-digit 3) not-teens) "rd"
:else "th")))))))
navigator))