extend basic math function to multi params

This commit is contained in:
Quentin Leonetti 2019-07-13 21:27:40 +02:00
parent 0dc0db98a9
commit 82827a300b
2 changed files with 13 additions and 8 deletions

View File

@ -94,18 +94,18 @@ function Library (ronin) {
// Math
this.add = function (a, b) {
return a + b
this.add = function (...args) {
return args.reduce((sum, val) => sum + val)
}
this.sub = function (a, b) {
return a - b
this.sub = function (...args) {
return args.reduce((sum, val) => sum - val)
}
this.mul = function (a, b) {
return a * b
this.mul = function (...args) {
return args.reduce((sum, val) => sum * val)
}
this.div = function (a, b) {
return a / b
this.div = function (...args) {
return args.reduce((sum, val) => sum / val)
}
}

5
examples/math.lisp Normal file
View File

@ -0,0 +1,5 @@
(
(echo (add 2 3))
(echo (sub 22 3 4 5))
(echo (mul 2 3 4 5))
)