Skip to content

Standard library

Raven ships a batteries-included standard library. Every module is bundled into the compiler, so there is nothing to install: just import what you need. This page explains how imports work and the conventions shared across modules, then links to a reference page for each one.

How modules are imported

Bring a module's functions into scope by name with from, or import the module and call through its name:

from std.math import sqrt
import std.fs

fun main() {
    print(sqrt(16.0)) // 4.0
    print(fs.exists("missing.txt")) // false
}

str methods (split, strip, upper, replace, ...), dict and set, and Result/Option helpers are part of the prelude, like the builtins print, len, range, and sorted, so they need no import:

fun main() {
    let counts = {"a": 1}
    counts["b"] = 2
    print("a,b".split(","), "  hi ".strip().upper(), len(counts))
}

Core traits are always in scope

std.core defines the foundational traits (ToString, Eq, Ord, Hash, Iterator[T]) and implements them for the primitive types. It is auto-imported, so you never write import std.core:

fun describe[T: ToString](x: T) -> str = x.to_string()

See core traits for the full set.

Errors use Result and Option

Anything that can fail returns Result[T, Error]; anything that can be absent returns Option[T]. There are no exceptions and no null. Handle a Result with match, or propagate it with the ? operator inside a function that itself returns Result:

from std.fs import read

fun load(path: str) -> Result[str, Error] {
    let text = read(path)? // returns early on Err
    return Ok(text.trim())
}

fun main() {
    match load("note.txt") {
        case Ok(s) { print(s) }
        case Err(e) { print("could not load") }
    }
}

See std.error for Error, ?, and the Result/Option helpers.

The modules

Text and formatting

Module What it is for
std.string methods on str: slicing, case, search, replace
std.fmt padding, joining, number bases, the Debug trait
std.regex regular expressions
std.encoding hex and base64

Data structures and iteration

Module What it is for
std.collections hash-backed dict and set
std.list utility functions over the built-in list
std.option combinators over the built-in Option
std.iter lazy iterator adapters and consumers
std.cmp sorting and comparison helpers
std.hash non-cryptographic hashing

Numbers

Module What it is for
std.math float and integer math, constants
std.random a seeded random number generator

Input, output, and the system

Module What it is for
std.io console input and output
std.fs files and directories
std.path path string manipulation (no IO)
std.env environment, arguments, platform
std.process run external programs
std.time timestamps and calendar conversions

Networking

Module What it is for
std.net TCP sockets
std.http an HTTP client and server
std.tls verified TLS streams and STARTTLS upgrades
std.json JSON parse and stringify

Concurrency, errors, FFI, testing

Module What it is for
std.sync channels for goroutines
std.error the Error type and Result helpers
std.ffi bridge values to C and access raw memory
std.test assertions for test programs
std.core the always-in-scope core traits