Lake

Standard library

Lake's standard library is written in Lake, on top of a thin layer of direct syscalls — there is no libc and no garbage collector. Memory comes from each process's own arena and is reclaimed when the process ends. Below are the pieces you reach for most often. Import what you need from the std.* modules.

§Vec — growable array

Vec[T] is a generic dynamic array backed by a single buffer; it doubles its capacity on growth.

lake
+std.vec.{ Vec vec_new vec_push vec_get vec_len }

main is {
  _ -> {
    let v0 Vec[i64] = vec_new()
    let v1 = vec_push(v0 10)
    let v2 = vec_push(v1 20)
    let v3 = vec_push(v2 30)
    let n = vec_len(v3)          # 3
    let x = v3[2]                # 30  — `[]` is the Index protocol
  }
}

v[i] works because Vec is Index (see protocols). vec_push returns the (possibly relocated) vector, so thread the result through.

§String and buf

buf is the primitive byte buffer. std.strings builds on it with allocation-aware helpers, and std.string provides a growable String:

lake
+std.strings.{ concat int_to_buf }

main is {
  _ -> {
    let greeting = concat("hello, " "lake")   # "hello, lake"
    let n = int_to_buf(42)                     # "42"
  }
}

§IntMap — hash map

IntMap[V] maps integer keys to values using open addressing with a power-of-two table and FNV hashing:

lake
+std.hashmap.{ IntMap intmap_new intmap_put intmap_get }

main is {
  _ -> {
    let m0 IntMap[i64] = intmap_new()
    let m1 = intmap_put(m0 1 100)
    let m2 = intmap_put(m1 2 200)
    let v = intmap_get(m2 2)         # 200
  }
}

§Option, Result, panic

The error-handling types and the abort path live in std.option, std.result and std.panic — covered in error handling.

§Crypto

std.crypto implements SHA-256, HMAC-SHA256 and PBKDF2 in pure Lake — zero-allocation, suitable for protocols like SCRAM. The PostgreSQL client (see packages) uses them for authentication.

§Why a Lake-native stdlib?

Because the library is Lake all the way down, a program links only what it uses and carries no runtime. A non-trivial service — the URL-shortener demo using actors and PostgreSQL — compiles to a self-contained binary of about 1.5 MB.

§Key ideas

  • The stdlib is written in Lake over direct syscalls — no libc, no GC.
  • Containers are generic: Vec[T], IntMap[V]; v[i] via the Index protocol.
  • Strings build on buf; std.strings / std.string add helpers.
  • std.crypto (SHA-256/HMAC/PBKDF2) is pure-Lake and zero-alloc.