Carp/core/Tuples.carp
GrayJack 783167bb27 Modify the functions Array.maximum and Array.minimum to be safe
- Also made zero function for Pair so we don't lose compatibility with
   it
2019-05-13 21:41:45 -03:00

44 lines
949 B
Plaintext

(deftype (Pair a b) [a a b b])
(defmodule PairRef
(defn = [p1 p2]
(and (= (Pair.a p1) (Pair.a p2))
(= (Pair.b p1) (Pair.b p2))))
(defn /= [p1 p2]
(not (PairRef.= p1 p2)))
(defn < [p1 p2]
(if (= (Pair.a p1) (Pair.a p2))
(< (Pair.b p1) (Pair.b p2))
(< (Pair.a p1) (Pair.a p2))))
(defn > [p1 p2]
(PairRef.< p2 p1)))
(defmodule Pair
(defn init-from-refs [r1 r2]
(Pair.init @r1 @r2))
(defn = [p1 p2]
(and (= (Pair.a &p1) (Pair.a &p2))
(= (Pair.b &p1) (Pair.b &p2))))
(defn /= [p1 p2]
(not (Pair.= p1 p2)))
(defn < [p1 p2]
(PairRef.< &p1 &p2))
(defn > [p1 p2]
(PairRef.> &p1 &p2))
(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)))
(doc zero "return default values of the type inside `Pair`")
(defn zero []
(Pair.init (zero) (zero)))
)