kex docs Standard Library

Prelude

The standard-library surface automatically visible to every Kex source file.

Prelude names require no using at the call site. This includes everyday values and operations (List, Map, String, Math, IO), language-level protocols (Enumerable, Truthyable, Errorable), and core runtime services such as processes and time. For example, .map, conditions, and .try work without importing the traits that define them.

Being useful is not enough for inclusion. Every prelude name occupies global scope in every program, so a module belongs here only when ordinary Kex code needs it pervasively or the language model depends on it.

Modules stay opt-in when they expose a capability that should be visible in a file's dependencies, or when most programs do not need their vocabulary. Examples include the filesystem (FS), regular expressions (Regex), JSON, parser combinators (Parsing), bit operations (Bits), data structures such as Data.Set, hashing (Digest), command-line parsing (OptionParser), and the sandboxed evaluator (Evaluator).

using FS

main do
  let config = FS.File.read("config.txt").or("")
  IO.printLine(config)
end

Keep this file declarative. Each bare using names a sibling stdlib source; the toolchain expands those sources in order when it builds or loads the prelude. Put documentation for an individual type or operation beside its declaration in that source file, not here.

Modules in the prelude

29 module(s), visible in every file with no import.

  • Algebra
  • Atom Atoms are named values such as :ok, :error, and :reset. Use them for labels, statuses, and message tags. Atoms with the same name are equal; an atom and a string are different values.
  • Binary
  • Blankable
  • Comparable
  • Console ANSI terminal styling: colors, text attributes, and cursor control.
  • Enumerable
  • Env
  • Errorable
  • Feed Constructors for Feed.
  • FileHandle
  • IO Console input and output.
  • Kex The running toolchain, which backend, which version, which features.
  • List
  • Map
  • Math Mathematical constants and functions.
  • Number Reading a number out of text without deciding in advance which half of the numeric tower it belongs to.
  • Optional
  • Process Spawning servers, running external commands, and the ambient process operations.
  • Range
  • Stream Constructors for Stream.
  • String Constructors for String values that are built from something other than text: a Unicode codepoint, or raw UTF-8 bytes.
  • System The running process and the machine under it: exiting, and asking what platform this is.
  • Time Building times of day, controlling the clock in tests, and the calendar arithmetic the rest of this file is written on.
  • Test
  • TaggedValidation Diagnostics returned by compile-time validators for tagged literals.
  • Truthyable
  • Type Building and obtaining Type values.
  • Units Time-unit constructors, also available directly from the prelude.