Get started
From nothing to a running program in a few minutes, on Windows x64.
1. Get kon.exe
There is no public download yet, because Kon has not been released. For now kon.exe is built from the source, as the Tools page shows.
Put kon.exe in a folder of your own, such as C:\Kon, and add that folder to your PATH. Nothing else has to be installed. The first command unpacks the toolchain, which takes 10 to 15 seconds and about 310 MB.
2. Your first program
Make a file called hello.kon:
func main(): i32 {
print("xin chào")
return 0
}
Run it:
kon run hello.kon
3. Make an .exe
kon build hello.kon --release
This makes hello.exe, about 90 KB. It runs on another Windows machine with nothing of Kon installed.
4. Set up the editor
Install the VS Code extension. A run button appears at the top right, F5 runs the file, saving formats it, and errors are underlined on their line.
5. Your first error
Kon checks who owns each value. Hand a list over with take, then try to use it:
func main(): i32 {
var items: List<u8> = list[]
let other = take items
print(items.length)
return 0
}Line 4 uses items after line 3 gave it away. Use other instead and it builds. Every error is explained here.
6. A small real program
This keeps a count between runs in a JSON file. It uses the library that comes with kon.exe, with nothing to copy and no flags to add.
import "std/json.kon" as json
func main(): i32 {
let saved = json.load("count.json")
let before = saved.numberOr(saved.get(saved.root(), "runs"), 0.0)
var doc = json.document()
let root = doc.newObject()
doc.setRoot(root)
let runs = doc.newNumber(before + 1.0)
let added = doc.set(root, "runs", runs)
if !doc.save("count.json") { return 1 }
print(before + 1.0)
return 0
}
7. Start a project
For anything with more than one file, make a project. Inside it, the commands need no file name. More on projects.
kon new game
cd game
kon run
kon test