Syntax: The main function
● Beginner3 min
A program starts at fn main(). In a single-file script, the lines at the top level are main.
fn main() {
greet("Asha")
greet("Ravi")
}
fn greet(name: String) {
print("Hello, {name}")
}The program ran and printed:
kavach run main.kav
Hello, AshaHello, Ravi
main calls greet although greet is written below it: functions and types can be used anywhere in their file. Local variables are different: they exist only from their line on.
Scripts
For a quick script, leave main out. The lines at the top level become its body:
print("Hello, Kavach!")
const year = 2026
print("Written in {year}")The program ran and printed:
kavach run script.kav
Hello, Kavach!Written in 2026