diff options
author | Rich Hickey <richhickey@gmail.com> | 2008-08-06 20:27:52 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2008-08-06 20:27:52 +0000 |
commit | 05e3347604a3f7d192c6256624665af3a611f66b (patch) | |
tree | 99eb973969f35f5fc1b4443ffcae178d7ca27d48 /src | |
parent | 5c97b610426556b6d032084f1dc601e85000f829 (diff) |
added multi-arg support for = and not=.
Added none=.
Diffstat (limited to 'src')
-rw-r--r-- | src/clj/clojure/boot.clj | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/clj/clojure/boot.clj b/src/clj/clojure/boot.clj index 0d00e017..893db427 100644 --- a/src/clj/clojure/boot.clj +++ b/src/clj/clojure/boot.clj @@ -405,19 +405,30 @@ ;;;;;;;;;;;;;;;;at this point all the support for syntax-quote exists;;;;;;;;;;;;;;;;;;;;;; (defn = - "Equality. Returns true if obj1 equals obj2, false if not. Same as - Java obj1.equals(obj2) except it also works for nil, and compares + "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 in a type-independent manner. Clojure's immutable data structures define equals() (and thus =) as a value, not an identity, comparison." {:tag Boolean - :inline (fn [x y] `(. clojure.lang.Util equal ~x ~y))} - [x y] (. clojure.lang.Util (equal x y))) + :inline (fn [x y] `(. clojure.lang.Util equal ~x ~y)) + :inline-arities #{2}} + ([x y] (. clojure.lang.Util (equal x y))) + ([x y & more] + (if (= x y) + (if (rest more) + (recur y (first more) (rest more)) + (= y (first more))) + false))) (defn not= "Same as (not (= obj1 obj2))" {:tag Boolean} - [x y] (not (= x y))) + ([x y] (not (= x y))) + ([x y & more] + (not (apply = x y more)))) + + (defn compare "Comparator. Returns 0 if x equals y, -1 if x is logically 'less @@ -2861,3 +2872,18 @@ not-every? (comp not every?)) :ancestors (tf (:ancestors h) tag td parent ta) :descendants (tf (:descendants h) parent ta tag td)} h)))) + + +(defn none= + "Returns true if none of the arguments are equal" + {:tag Boolean} + ([x y] (not (= x y))) + ([x y & more] + (if (not= x y) + (loop [s #{x y} [x & etc :as xs] more] + (if xs + (if (contains? s x) + false + (recur (conj s x) etc)) + true)) + false))) |