diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 91f2d533..7cda9497 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -692,7 +692,7 @@ fyx (f y x)] (- fyx)) (compare-primitive x y))) -(defn compare-reduce- [op & xs] +(defn compare-reduce- [op xs] (var r true) (loop [i :range [0 (- (length xs) 1)] :let [c (compare (xs i) (xs (+ i 1))) @@ -705,27 +705,27 @@ (defn compare= "Equivalent of '=' but using compare function instead of primitive comparator" [& xs] - (compare-reduce- := xs)) + (compare-reduce- = xs)) (defn compare< "Equivalent of '<' but using compare function instead of primitive comparator" [& xs] - (compare-reduce- :< xs)) + (compare-reduce- < xs)) (defn compare<= "Equivalent of '<=' but using compare function instead of primitive comparator" [& xs] - (compare-reduce- :<= xs)) + (compare-reduce- <= xs)) (defn compare> "Equivalent of '>' but using compare function instead of primitive comparator" [& xs] - (compare-reduce- :> xs)) + (compare-reduce- > xs)) (defn compare>= "Equivalent of '>=' but using compare function instead of primitive comparator" [& xs] - (compare-reduce- :>= xs)) + (compare-reduce- >= xs)) ### ### diff --git a/test/suite0.janet b/test/suite0.janet index 20b13465..67fe8a87 100644 --- a/test/suite0.janet +++ b/test/suite0.janet @@ -345,9 +345,11 @@ (assert (= 1 (compare "foo" "bar")) "compare strings (1)") (assert (compare< 1 2 3 4 5 6) "compare less than integers") +(assert (not (compare> 1 2 3 4 5 6)) "compare not greater than integers") (assert (compare< 1.0 2.0 3.0 4.0 5.0 6.0) "compare less than reals") (assert (compare> 6 5 4 3 2 1) "compare greater than integers") (assert (compare> 6.0 5.0 4.0 3.0 2.0 1.0) "compare greater than reals") +(assert (not (compare< 6.0 5.0 4.0 3.0 2.0 1.0)) "compare less than reals") (assert (compare<= 1 2 3 3 4 5 6) "compare less than or equal to integers") (assert (compare<= 1.0 2.0 3.0 3.0 4.0 5.0 6.0) "compare less than or equal to reals") (assert (compare>= 6 5 4 4 3 2 1) "compare greater than or equal to integers") @@ -370,9 +372,9 @@ @{:type :mynum :v 0 :compare (fn [self other] (case (type other) - :number (compare-primitive (self :v) other)) + :number (compare-primitive (self :v) other) :table (when (= (get other :type) :mynum) - (compare-primitive (self :v) (other :v))))}) + (compare-primitive (self :v) (other :v)))))}) (let [n3 (table/setproto @{:v 3} mynum)] (assert (= 0 (compare 3 n3)) "compare num to object (1)") @@ -384,5 +386,6 @@ (assert (compare= 3 n3 (table/setproto @{:v 3} mynum)) "compare= poly") (assert (deep= (sorted @[4 5 n3 2] compare<) @[2 n3 4 5]) "polymorphic sort")) + (end-suite)