summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Orst <andreyorst@gmail.com>2020-11-09 22:33:42 +0300
committerAndrey Orst <andreyorst@gmail.com>2020-11-09 22:33:42 +0300
commit7ac429383b6fb61c24de2b7f9b1322dfdaea6f93 (patch)
tree83809b48c98f99db5e9609ef0fd640f637a3ac6f
parent40eeb480099fe238ae03566ae7167003789ea4c7 (diff)
fix(core): rename plus to add, minus to sub
-rw-r--r--core.fnl8
-rw-r--r--test/core.fnl60
2 files changed, 34 insertions, 34 deletions
diff --git a/core.fnl b/core.fnl
index fd25a02..d22beec 100644
--- a/core.fnl
+++ b/core.fnl
@@ -501,21 +501,21 @@ that would apply to that value, or `nil' if none apply and no default."
(or (. (getmetatable multifn) :multimethods dispatch-val)
(. (getmetatable multifn) :multimethods :default)))
-(fn* core.plus
+(fn* core.add
([] 0)
([a] a)
([a b] (+ a b))
([a b c] (+ a b c))
([a b c d] (+ a b c d))
- ([a b c d & rest] (apply plus (+ a b c d) rest)))
+ ([a b c d & rest] (apply add (+ a b c d) rest)))
-(fn* core.minus
+(fn* core.sub
([] 0)
([a] (- a))
([a b] (- a b))
([a b c] (- a b c))
([a b c d] (- a b c d))
- ([a b c d & rest] (apply minus (- a b c d) rest)))
+ ([a b c d & rest] (apply sub (- a b c d) rest)))
(fn* core.mul
([] 1)
diff --git a/test/core.fnl b/test/core.fnl
index f83e389..01a7e0c 100644
--- a/test/core.fnl
+++ b/test/core.fnl
@@ -55,8 +55,8 @@
: methods
: remove-method
: remove-all-methods
- : plus
- : minus
+ : add
+ : sub
: mul
: div
: le
@@ -229,7 +229,7 @@
"Alice Watson works as chief officer at Coffee With You"]))
(testing "reduce"
- (fn* plus
+ (fn* add
([] 0)
([a] a)
([a b] (+ a b))
@@ -239,16 +239,16 @@
(set res (+ res v)))
res))
- (assert-eq (reduce plus []) 0)
- (assert-eq (reduce plus [1]) 1)
- (assert-eq (reduce plus [1 2]) 3)
- (assert-eq (reduce plus (range 10)) 45)
- (assert-eq (reduce plus -3 (range 10)) 42)
- (assert-eq (reduce plus 10 []) 10)
- (assert-eq (reduce plus 10 [1]) 11)
- (assert-eq (reduce plus 10 nil) 10)
+ (assert-eq (reduce add []) 0)
+ (assert-eq (reduce add [1]) 1)
+ (assert-eq (reduce add [1 2]) 3)
+ (assert-eq (reduce add (range 10)) 45)
+ (assert-eq (reduce add -3 (range 10)) 42)
+ (assert-eq (reduce add 10 []) 10)
+ (assert-eq (reduce add 10 [1]) 11)
+ (assert-eq (reduce add 10 nil) 10)
(assert* (not (pcall reduce)))
- (assert* (not (pcall reduce plus)))
+ (assert* (not (pcall reduce add)))
(fn mapping [f]
(fn [reducing]
@@ -260,7 +260,7 @@
(reduce f (f init (first tbl)) (rest tbl))
init))
- (assert-eq (reduce plus (range 10)) (reduce- plus 0 (range 10))))
+ (assert-eq (reduce add (range 10)) (reduce- add 0 (range 10))))
(testing "filter"
(assert* (not (pcall filter)))
@@ -517,23 +517,23 @@
(assert* (not (pcall remove-all-methods f f)))))
(deftest math-functions
- (testing "plus"
- (assert-eq (plus) 0)
- (assert-eq (plus 1) 1)
- (assert-eq (plus -1) -1)
- (assert-eq (plus 1 2) 3)
- (assert-eq (plus 1 2 3) 6)
- (assert-eq (plus 1 2 3 4) 10)
- (assert-eq (plus 1 2 3 4 5) 15))
-
- (testing "minus"
- (assert-eq (minus) 0)
- (assert-eq (minus 1) -1)
- (assert-eq (minus -1) 1)
- (assert-eq (minus 1 2) -1)
- (assert-eq (minus 1 2 3) -4)
- (assert-eq (minus 1 2 3 4) -8)
- (assert-eq (minus 1 2 3 4 5) -13))
+ (testing "add"
+ (assert-eq (add) 0)
+ (assert-eq (add 1) 1)
+ (assert-eq (add -1) -1)
+ (assert-eq (add 1 2) 3)
+ (assert-eq (add 1 2 3) 6)
+ (assert-eq (add 1 2 3 4) 10)
+ (assert-eq (add 1 2 3 4 5) 15))
+
+ (testing "sub"
+ (assert-eq (sub) 0)
+ (assert-eq (sub 1) -1)
+ (assert-eq (sub -1) 1)
+ (assert-eq (sub 1 2) -1)
+ (assert-eq (sub 1 2 3) -4)
+ (assert-eq (sub 1 2 3 4) -8)
+ (assert-eq (sub 1 2 3 4 5) -13))
(testing "mul"
(assert-eq (mul) 1)