Added variadic functions

TOKEN_DOT_DOT_DOT was added to the lexer
variadic.cosmo was added to the examples directory
This commit is contained in:
2020-12-26 22:01:22 -06:00
parent db8ed21746
commit 090cc62cce
7 changed files with 58 additions and 11 deletions

15
examples/variadic.cosmo Normal file
View File

@@ -0,0 +1,15 @@
// adds all args passed (expects numbers)
function add(start, ...args)
// starting at `start`, add up all numbers passed
local total = start
for val in args do
total = total + val
end
return total
end
print("add(100) -> " .. add(100))
print("add(100, 1, 2, 3, 4) -> " .. add(100, 1, 2, 3, 4))
print("add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) -> " .. add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
print("add(-54, 2, 3, 4, 5, 6, 7, 8, 9, 10) -> " .. add(-54, 2, 3, 4, 5, 6, 7, 8, 9, 10))