Skip to content

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(...)
ModuleWhat it coversAvailability
std/ioStandard input and outputeverywhere
std/convConverting values to and from stringseverywhere
std/strString searching, splitting, and transformingeverywhere
std/mathInteger and floating-point math, random numberseverywhere
std/timeSleeping and reading clockseverywhere
std/itermap / filter / reduce over arrayseverywhere
std/algorithmGeneric sorting and binary searcheverywhere
std/collectionsStack, queue, list, set, and mapeverywhere
std/termTerminal control, raw mode, key inputeverywhere (raw input native)
std/fsFiles and directoriesnative (files also on Node)
std/envEnvironment variables and command-line argsnative (get also on Node)
std/procRunning commands, exitingnative (run, exit also on Node)
std/netTCP and UDP sockets, TLS clients and serversnative
std/threadThreads, mutexes, condition variablesnative

“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.

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() is none at end of input, fs.open is none for a missing file, map.get is none for an absent key. Check against none, then unwrap with !.
  • bool for success. Operations where you only need to know whether it worked, such as fs.mkdir, env.set, and socket.send_all, return true on 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.