Standard Library
The standard library is a set of modules written in Kora and shipped with the compiler. Import a module by path. It is named after its last path segment unless you rename it:
import "std/math"; # math.abs(...), math.gcd(...)import "std/math" m; # renamed: m.abs(...)Modules
Section titled “Modules”| Module | What it covers | Availability |
|---|---|---|
| std/io | Standard input and output | everywhere |
| std/conv | Converting values to and from strings | everywhere |
| std/str | String searching, splitting, and transforming | everywhere |
| std/math | Integer and floating-point math, random numbers | everywhere |
| std/time | Sleeping and reading clocks | everywhere |
| std/iter | map / filter / reduce over arrays | everywhere |
| std/algorithm | Generic sorting and binary search | everywhere |
| std/collections | Stack, queue, list, set, and map | everywhere |
| std/term | Terminal control, raw mode, key input | everywhere (raw input native) |
| std/fs | Files and directories | native (files also on Node) |
| std/env | Environment variables and command-line args | native (get also on Node) |
| std/proc | Running commands, exiting | native (run, exit also on Node) |
| std/net | TCP and UDP sockets, TLS clients and servers | native |
| std/thread | Threads, mutexes, condition variables | native |
“Everywhere” means the native backend, Node, and the browser playground. The playground additionally provides graphics and input functions that are not part of the standard library.
Conventions
Section titled “Conventions”The library reports failure through types, not exceptions:
T?for absence or failure. Anything that can legitimately come up empty returns an optional:io.input()isnoneat end of input,fs.openisnonefor a missing file,map.getisnonefor an absent key. Check againstnone, then unwrap with!.boolfor success. Operations where you only need to know whether it worked, such asfs.mkdir,env.set, andsocket.send_all, returntrueon success.- Panics for programmer errors. Popping an empty stack or indexing out of bounds stops the program with a message. These are bugs, not conditions to handle.
Generic functions and containers take explicit type arguments with the
turbofish: iter.map::<int, string>(xs, f), stack.make::<int>(). Hashing is
handled for you by std/collections, which reaches for an
int __hash__(self) method on your own types. Where an ordering is needed you
supply it as a small struct with a less method, see
std/algorithm.