2018-06-01 12:18:03 +03:00
|
|
|
(deftype (Pair a b) [a a b b])
|
|
|
|
|
2018-12-09 19:34:10 +03:00
|
|
|
(defmodule PairRef
|
|
|
|
(defn = [p1 p2]
|
|
|
|
(and (= (Pair.a p1) (Pair.a p2))
|
|
|
|
(= (Pair.b p1) (Pair.b p2))))
|
2020-05-10 20:32:22 +03:00
|
|
|
(implements = PairRef.=)
|
2018-12-09 19:34:10 +03:00
|
|
|
|
|
|
|
(defn < [p1 p2]
|
|
|
|
(if (= (Pair.a p1) (Pair.a p2))
|
|
|
|
(< (Pair.b p1) (Pair.b p2))
|
|
|
|
(< (Pair.a p1) (Pair.a p2))))
|
2020-05-10 20:32:22 +03:00
|
|
|
(implements < PairRef.<)
|
2018-12-09 19:34:10 +03:00
|
|
|
|
|
|
|
(defn > [p1 p2]
|
|
|
|
(PairRef.< p2 p1)))
|
2020-05-19 23:54:36 +03:00
|
|
|
(implements > PairRef.>)
|
2018-12-09 19:34:10 +03:00
|
|
|
|
2018-06-01 12:18:03 +03:00
|
|
|
(defmodule Pair
|
|
|
|
(defn init-from-refs [r1 r2]
|
|
|
|
(Pair.init @r1 @r2))
|
|
|
|
|
2018-12-07 22:24:36 +03:00
|
|
|
(defn = [p1 p2]
|
|
|
|
(and (= (Pair.a &p1) (Pair.a &p2))
|
|
|
|
(= (Pair.b &p1) (Pair.b &p2))))
|
2020-05-10 20:32:22 +03:00
|
|
|
(implements = Pair.=)
|
2018-12-07 22:24:36 +03:00
|
|
|
|
2018-12-09 19:34:10 +03:00
|
|
|
(defn < [p1 p2]
|
|
|
|
(PairRef.< &p1 &p2))
|
2020-05-10 20:32:22 +03:00
|
|
|
(implements < Pair.<)
|
2018-12-07 22:24:36 +03:00
|
|
|
|
2018-12-09 19:34:10 +03:00
|
|
|
(defn > [p1 p2]
|
|
|
|
(PairRef.> &p1 &p2))
|
2020-05-10 20:32:22 +03:00
|
|
|
(implements > Pair.>)
|
2018-06-01 12:18:03 +03:00
|
|
|
|
2019-05-05 12:49:30 +03:00
|
|
|
(doc reverse "reverses a `Pair` `p` such that its first member is its second member and vice versa.")
|
|
|
|
(defn reverse [p]
|
|
|
|
(Pair.init @(Pair.b p) @(Pair.a p)))
|
2019-05-14 03:41:45 +03:00
|
|
|
|
|
|
|
(doc zero "return default values of the type inside `Pair`")
|
|
|
|
(defn zero []
|
|
|
|
(Pair.init (zero) (zero)))
|
|
|
|
)
|