Your first program
Make a file hello.kova:
fn main { print("Hello, Kova!")}Run it:
kova run hello.kovaHello, Kova!fn main is where every program starts. It has no (): in Kova, a function without parameters
is written and called without parentheses (you will meet x.to_float and rex.sound the same
way). print writes a line.
Run or build
Section titled “Run or build”There are two ways to start a program, and they always print the same thing:
kova run hello.kovastarts it at once. Kova reads the program, checks it, and runs it in its own interpreter. This is what you use while writing.kova build hello.kovamakes a native executable,hello(hello.exeon Windows), next to the file. It is a small file (about 30 KB here) that runs on its own, on any machine of that system, without Kova installed:
kova build hello.kova./hello✓ hello (Linux, 29 KB) in 3 msHello, Kova!Add --target windows (or linux, mac…) to make the executable for another system, from any
system. Building lists them all.
Giving the program words
Section titled “Giving the program words”What follows the file name on the command line reaches the program as system.args, a list of texts:
import system
fn main { for word in system.args { print("Hello, {word}!") }}kova run hello.kova Ada AlanHello, Ada!Hello, Alan!{word} inside a text puts the value of word there.
When something is wrong
Section titled “When something is wrong”Kova checks the whole program before running any of it. A mistake is shown with its place and, often, a way out:
fn main { let name: String := "Ada" print("Hello, " + name.length)}error: different types: `String` expected, `Int` given --> main.kova:3:23 |3 | print("Hello, " + name.length) | ^^^^^^^^^^^ = help: put the value inside the text: `"total: {x}"`name.length is a number, and + joins texts only with texts: Kova never turns one type into
another without being asked. Here, write "Hello, {name.length}", or name.length.to_string.
In the editor, the same message appears under the code while you type.
Messages are written in English or in French: Kova follows your system’s language (LANG). To choose, set KOVA_LANG=en or KOVA_LANG=fr before the command, or write header { lang := en } in the program: environment variables.
A program can also stop while it runs: an index past the end of a list, a number too large for an
Int, a contract that fails. It then says what happened and where,
and ends with the exit code 101.
Next: a tour of Kova, or go straight to the language guide.