A fresh new minor release of ABS: always be shipping! 🚢
Optional function parameters
You can now make a parameter optional by specifying its
default value:
f greet(name, greeting = "hello") {
echo("$greeting $name!")
}
greet("user") # hello user!
greet("user", "hola") # hola user!
A default value can be any expression (doesn't have to be a literal):
f test(x = 1){x}; test() # 1
f test(x = "test".split("")){x}; test() # ["t", "e", "s", "t"]
f test(x = {}){x}; test() # {}
y = 100; f test(x = y){x}; test() # 100
x = 100; f test(x = x){x}; test() # 100
x = 100; f test(x = x){x}; test(1) # 1
Note that mandatory arguments always need to be declared
before optional ones:
f(x = null, y){}
# parser errors:
# found mandatory parameter after optional one
# [1:13] f(x = null, y){}
Descending number ranges
Number ranges (x..y
) now support generating ranges in descending order:
3..1 # [3, 2, 1]
See ya! 👋