mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
37 lines
673 B
Plaintext
37 lines
673 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))
|
|
|
|
)
|