LLuce

Hello and arguments

The smallest useful program: main, print, and a string.

main.luc
func main():
    print("hello, loom")
Output
hello, loom

arg_count() and arg(i) reach the command line. arg(i) outside the range traps, and the count is right there to check against.

main.luc
func main():
    if arg_count() == 0:
        print("usage: greet NAME [NAME ...]")
        return
    for index in range(0, arg_count()):
        print(f"{index + 1}. hello, {arg(index)}")
Output
1. hello, fig
2. hello, pear
3. hello, plum

Arguments arrive as Strings. Turning one into a number is parse_int, which answers an Int? because the text may not be a number at all — else supplies the fallback.

main.luc
func main():
    let times = parse_int(arg(0)) else 1
    for i in range(0, times):
        print(f"line {i}")
Output
line 0
line 1
line 2
line 3