1
0
mirror of https://github.com/janet-lang/janet synced 2024-10-18 16:05:47 +00:00

Merge pull request #1480 from pyrmont/bugfix.fallback-compare

Fix fallback support in polymorphic compare
This commit is contained in:
Calvin Rose 2024-07-31 06:05:27 -07:00 committed by GitHub
commit d1104b5a65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -819,11 +819,17 @@
(defmacro- do-compare (defmacro- do-compare
[x y] [x y]
~(if (def f (get ,x :compare)) ~(do
(f ,x ,y) (def f (get ,x :compare))
(if (def f (get ,y :compare)) (def f-res (if f (f ,x ,y)))
(- (f ,y ,x)) (if f-res
(cmp ,x ,y)))) f-res
(do
(def g (get ,y :compare))
(def g-res (if g (- (g ,y ,x))))
(if g-res
g-res
(cmp ,x ,y))))))
(defn compare (defn compare
``Polymorphic compare. Returns -1, 0, 1 for x < y, x = y, x > y respectively. ``Polymorphic compare. Returns -1, 0, 1 for x < y, x = y, x > y respectively.