~subsetpark/ec

ref: 3fcb736eaa84bebba6dd5dbb56d7fe8d030d5cf2 ec/src/operations.janet -rw-r--r-- 516 bytes
3fcb736e — Zach Smith Add swap 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(import /src/calc)

(defmacro defop
  [name arity f]
  ~(def ,name (:new calc/Operation
                    :arity ,arity
                    :type ,(keyword name)
                    :fun-ref ,f)))

(defop add 2 +)
(defop sub 2 -)
(defop div 2 /)
(defop mul 2 *)
(defop sqrt 1 math/sqrt)
(defop lt 2 (fn [x y] (if (< x y) 1 0)))
(defop gt 2 (fn [x y] (if (> x y) 1 0)))
(defop lte 2 (fn [x y] (if (<= x y) 1 0)))
(defop gte 2 (fn [x y] (if (>= x y) 1 0)))
(defop eq 2 (fn [x y] (if (= x y) 1 0)))
(defop cmp 2 cmp)