Skip to content
Kavachकवच

Your First Program

Also known as: first program getting started main entry point hello world print tutorial

● Beginner5 minBefore this: InstallSpec 1.3

Write a file, run it, and turn it into a program anyone can start.

Every Kavach program starts at fn main(). The lines between its braces run from top to bottom.

fn main() {
    print("namaste, duniya")
    const languages = ["Kavach", "Rust", "Python"]
    print(languages.len())
}

The program ran and printed:

kavach run hello.kav

namaste, duniya3
hello.kav: Kavach code, then what running it prints

Run it

Save the code as hello.kav, open a terminal in the same folder, and type kavach run hello.kav. The two lines above appear.

Make an executable

kavach build hello.kav compiles the same file to machine code and writes hello (hello.exe on Windows). That file is the whole program: give it to someone with the same kind of machine and it runs there without Kavach.

kavach run while you write, kavach build when you ship. Both give the same output.

Try it yourself

Change the program so it prints your own name on the first line.
Show the answer

Replace the text inside the first print(…), keeping the quotes: print("Asha").

Check yourself

QUIZ 1 / 1pick one
You wrote hello.kav. Which command makes a file you can give to someone without Kavach?