// A small CLI tool: count lines and words in files. import os struct Stats { lines: int words: int } func count(path: string): (Stats, error) { var text = os.read_file(path)? // ? returns the error to the caller var stats = Stats{} for line in text.lines() { stats.lines += 1 stats.words += line.fields().len() } return stats, nil } func main() { var args = os.args for path in args[1..] { var s, err = count(path) if err != nil { print("{path}: error: {err}") continue } print("{path}: {s.lines} lines, {s.words} words") } }