Clojure vectors have an unusual property that when comparing their length, the vector is considered before any other property. In particular. Haskell
Prelude> [1, 3] > [1, 2, 3] True
and Ruby
1.9.3p392 :003 > [1, 3] <=> [1, 2, 3] => 1
But in Clojure:
user=> (compare [1, 3] [1, 2, 3]) -1
Now you can implement the βnormalβ comparison yourself:
(defn vector-compare [[value1 & rest1] [value2 & rest2]] (let [result (compare value1 value2)] (cond (not (= result 0)) result (nil? value1) 0 ; value2 will be nil as well :else (recur rest1 rest2))))
but I expect that this way of comparing vectors is so common that there is a standard way to achieve this. There is?
source share