Captain / Documentation / Part 6. The standard library

The standard library

Contents ↓

This part is a reference. It lists what a Captain program can call: the operations every program has, the modules the compiler knows by name, and the source modules shipped in the repository's lib/ directory. Each entry gives its signature and a sentence or two on what it does. The chapters in Part 3 and Part 4 explain the ideas; this part says what exists.

Three layers

Layer What it is How you get it
The prelude Operations on built-in values (Text, List, Octets, Decimal, quantities, bool, Option, Result), the conversions as:, parse: and Text from:, and the root effects (exec, http, readFileText, ...). Always in scope. No use.
Compiler-known modules Name tables the compiler supplies when a program says use Std::Json., use Std::Text., use Std::EcmaNumber. and a few others. They have no .capt source. use the module, then call its names as the module documents.
Source modules Ordinary Captain modules under lib/: Std::Utc, System::File, Tool::Curl, Worker::Http, App::Ui and others. use the module, call its exports qualified by the module's last segment (Utc::leap year: y), and give the compiler the source with -I.

Using library modules shows how to import, call, check and build with each layer.

How mature it is

The prelude and the compiler-known modules are part of the toolchain. They change only with the compiler, and a change that would alter what an existing artifact means is a new VM generation (see below).

The source modules are younger. lib/README.md calls the lib/std/ modules candidates: pure Captain code that works and is tested, but is not yet a published interface. The System:: and Tool:: modules are written as production wrappers, but there is no package or version publication for any of them yet: you build against the source in your checkout. Expect names and signatures in lib/ to move more than anything in the prelude.

VM generations

An artifact records the lowest VM generation it needs, and the compiler raises it only when the program uses something newer. Most entries below run on any generation. Where an entry needs more, its table says so:

Generation Added
3 everyday text and list operations, writeFileText, createFileText, listDirectory
4 Octets, text ordering with <, decoding JSON into Option fields
5 Json decodeStrict:..., observeFileDigest
6 (t characters); Json decode:as: with a list or scalar target
7 the remaining file and process effects, Octets slicing and decoding, Json members:..., Json reencodeEcma:..., Std::EcmaNumber, exact decimal division and rounding, the numeric conversions n as: Decimal and n as: i64

captain inspect prints the generation an artifact needs (vm 7). VM generations in Part 9 says which release of the toolchain and SDK runs which generation.

Pages

  1. Using library modules: use, qualified calls, -I, and reading a module's surface with captain inspect.
  2. Text, lists and logic: Text, List, bool, Option, Result, Int parse:, Text from:.
  3. Numbers, tagged values and secrets: Decimal, quantities, Money per:, numeric as:, parse: on tagged types, Secret named:, and Err.
  4. Octets and digests: Octets, hex, SHA-256, integer encodings.
  5. JSON and number text: Std::Json, writing JSON with #{…} and Json text:, Std::EcmaNumber, Std::Text.
  6. Processes, HTTP and hosts: exec, shell, observeProcess, observeProcessLiveness, http, observe serverAt:.
  7. Files: the bounded file effects, reads, writes, listing, digests, streams, copies, moves and removal.
  8. Compiler-known modules: every module the compiler supplies, including the declaration surfaces Host::Debian, Provider::Aws and Platform::Gump.
  9. The Std source modules: Std::Utc, Std::TextUtilities, Std::TextLists, Std::JsonEncoding, Std::FileTree.
  10. System and tool modules: System::File, System::Diagnostics, System::Linux, System::RemoteLinux, System::RemoteFile, and the Tool:: wrappers.
  11. Worker, app and Gump modules: Worker::Http, App::Ui, and the Gump:: modules.