1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-24 09:17:17 +00:00

Fix polymorphic support in compare

This commit is contained in:
Michael Camilleri 2024-07-29 16:16:41 +09:00
parent 872b39cc32
commit 1f074671ce
No known key found for this signature in database
GPG Key ID: 7EB218A48DF8B572

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.