aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2025-03-18 12:16:24 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-18 12:16:24 +0000
commit942c2a5811798d6c6bbb66c17b3578cda84a565c (patch)
tree3f45eb54eab9623548bf3afa8240ce66bdfc435d
parentlanguage: [array] and {struct} literals (diff)
downloadalive-942c2a5811798d6c6bbb66c17b3578cda84a565c.tar.gz
alive-942c2a5811798d6c6bbb66c17b3578cda84a565c.zip
lib: unary math/+, math/*
-rw-r--r--alv-lib/math.moon4
-rw-r--r--spec/lib/math_spec.moon13
2 files changed, 15 insertions, 2 deletions
diff --git a/alv-lib/math.moon b/alv-lib/math.moon
index 2cf6e26..eaab36d 100644
--- a/alv-lib/math.moon
+++ b/alv-lib/math.moon
@@ -152,7 +152,7 @@ add = Constant.meta
summary: "Add values."
examples: { '(+ a b [c…])', '(add a b [c…])' }
description: "Sum all arguments."
- value: func_op (reduce_fn (a, b) -> a + b), num\rep 2, nil
+ value: func_op (reduce_fn (a, b) -> a + b), num*0
sub = Constant.meta
meta:
@@ -182,7 +182,7 @@ For every pair of arguments, from left to right:
- If both arguments are matrices, multiply them using matrix multiplication.
- `(* num[L][M] num[M][N]) → num[M][N]`"
value: class extends PureOp
- pattern: any!\rep 2, nil
+ pattern: any!*0
type: (inputs) =>
types = [input\type! for input in *inputs]
diff --git a/spec/lib/math_spec.moon b/spec/lib/math_spec.moon
index 40c7abd..038fc5a 100644
--- a/spec/lib/math_spec.moon
+++ b/spec/lib/math_spec.moon
@@ -153,6 +153,19 @@ describe "math", ->
(- [[1 2] [1 2]]
[1 2])'
+ describe "add, sub, mul", ->
+ it "handle single arguments", ->
+ COPILOT\eval_once '
+ (expect= [3 4 5]
+ (+ [3 4 5]))
+
+ (expect= [0 1 -2]
+ (- [0 -1 2]))
+
+ (expect= [1 2 3]
+ (* [1 2 3]))
+ '
+
describe "mul", ->
it "handles scalars and matrices", ->
with COPILOT\eval_once '