Hello World
import "std/io";
int main() { io.write("Hello, world!\n"); return 0;}Paste it into the playground and press Run, or save it as
hello.kora and compile it:
kora hello.kora -o hello && ./helloEither way it prints Hello, world!.
Line by line
Section titled “Line by line”import "std/io";pulls in the standard I/O module. Modules are imported by path and named after the last segment, so its functions areio.write,io.print, andio.input.int main()is the entry point. Every program starts atmain, which returns anintexit code. Return types come first:int, then the name.io.write("Hello, world!\n");writes a string to stdout with no trailing newline, hence the explicit\n. Astringis an array ofchar(bytes). (io.printadds the newline for you.)return 0;exits with success.
Reading input
Section titled “Reading input”io.input returns a string?, an optional, because input can end. Handle the
empty case before using the value:
import "std/io";
int main() { io.write("What is your name? "); let name = io.input(); if (name == none) { return 1; } io.write("Hello, "); io.write(name!); io.write("!\n"); return 0;}The ! force-unwraps the optional, safe here because the none case already
returned. In the playground, type into the Standard input box.
- Kora in 5 Minutes: the whole language in one pass.
- Standard Library: every module, with signatures and examples.