55 lines
1.1 KiB
Plaintext
55 lines
1.1 KiB
Plaintext
;; Basic arithmetic
|
|
(def +@2 (fun (x y) (@+ x y)))
|
|
(def +@3 (fun (x y z) (@+ x (@+ y z))))
|
|
(def +@4 (fun (x y z t) (@+ (@+ x y) (@+ z t))))
|
|
(def + +@2)
|
|
|
|
(def -@1 (fun (x) (@- 0 x)))
|
|
(def -@2 (fun (x y) (@- x y)))
|
|
(def - -@2)
|
|
|
|
|
|
;; Comparisons
|
|
(def <@2 (fun (x y) (@< x y)))
|
|
(def <@3 (fun (x y z) (and (@< x y) (@< y z))))
|
|
(def < <@2)
|
|
|
|
(def <=@2 (fun (x y) (@<= x y)))
|
|
(def <=@3 (fun (x y z) (and (@<= x y) (@<= y z))))
|
|
(def <= <=@2)
|
|
|
|
(def >@2 (fun (x y) (@< y x)))
|
|
(def >@3 (fun (x y z) (and (> x y) (> y z))))
|
|
(def > >@2)
|
|
|
|
(def >=@2 (fun (x y) (@<= y x)))
|
|
(def >=@3 (fun (x y z) (and (>= x y) (>= y z))))
|
|
(def >= >=@2)
|
|
|
|
(def = (fun (x y) (@= x y)))
|
|
(def != (fun (x y) (not (@= x y))))
|
|
|
|
(def int-min (fun (x y) (if (<= x y) x y)))
|
|
(def int-max (fun (x y) (if (>= x y) x y)))
|
|
|
|
|
|
|
|
|
|
(def %t (fun (x y) (@% x y)))
|
|
|
|
|
|
(def int-abs
|
|
(fun (i)
|
|
(if (< i 0) (- i) i)))
|
|
|
|
|
|
(def int-gcd
|
|
(fun (x y)
|
|
(rec loop ((x (int-abs x))
|
|
(y (int-abs y)))
|
|
(if (= 0 y)
|
|
x
|
|
(loop y (%t x y))))))
|
|
|
|
(int-gcd 548 65)
|