mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 15:43:01 +00:00 
			
		
		
		
	Fix polymorphic support in compare
This commit is contained in:
		| @@ -819,11 +819,17 @@ | ||||
|  | ||||
| (defmacro- do-compare | ||||
|   [x y] | ||||
|   ~(if (def f (get ,x :compare)) | ||||
|      (f ,x ,y) | ||||
|      (if (def f (get ,y :compare)) | ||||
|        (- (f ,y ,x)) | ||||
|        (cmp ,x ,y)))) | ||||
|   ~(do | ||||
|      (def f (get ,x :compare)) | ||||
|      (def f-res (if f (f ,x ,y))) | ||||
|      (if f-res | ||||
|        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 | ||||
|   ``Polymorphic compare. Returns -1, 0, 1 for x < y, x = y, x > y respectively. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Michael Camilleri
					Michael Camilleri