Cosmo/examples/variadic.cosmo
CPunch 8ac8085d20 syntax: 'var'->'let' 'function'->'func'
- 'var' has some weird scoping connotations with users of JS. better to change it to 'let', which will decide whether to make the variable a local or a global
- 'func' looks visually appealing lol
- some minor refactoring done in cparse.c
2023-02-09 15:58:25 -06:00

15 lines
495 B
Plaintext

// adds all args passed (expects numbers)
func 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))