Skip to content

stdlib and file embedding

The comptime subset of the stdlib covers the most common cases: string methods (trim, to_upper, to_lower, concatenation) and math.* functions (sqrt, pow, floor, etc.). Use them the same way you would at runtime — the difference is that everything happens inside the compiler.

Banner normalized with trim + to_upper and square root of 64 — both resolved at compile time.

06-string-and-math.zolo
Playground
// Feature: comptime stdlib bits — string methods and `math.*` work too

// Syntax: same `comptime { ... }` block; you can call a curated subset

// of stdlib helpers (string trim/upper, math.sqrt, etc.).

// When to use: bake banner strings, compile-time constants from

// numerical formulas, normalize identifiers at build time.


use std::math

let banner = comptime {
  let raw = "  Hello, Comptime!  "
  raw.trim().to_upper()
}

print(banner)

// expected: HELLO, COMPTIME!


let r = comptime math.sqrt(64.0)
print(r)
// expected: 8

Embedding files with comptime fs.read

comptime fs.read("path") reads a file during compilation and replaces the call with the resulting string. The path is always relative to the source file, not to the compiler's working directory.

Use this to embed templates, prompts, JSON schemas, SQL queries, or shaders directly into the binary. There is no fopen in production, no risk of a missing file at deployment, and no path-resolution work at runtime.

The result is a normal comptime string — you can chain it with other comptime methods in the same expression.

Reading a file at compile time and transforming the resulting string.

07-embed-file.zolo
Playground
// Feature: bake a file's contents into the program at compile time,
// reusing the runtime `std::fs` API under a `comptime` prefix.
// Syntax: `comptime fs.read("relative/path")` reads the file during
// compilation and replaces the call with the resulting string literal.
// Path resolution in comptime is **always relative to this source
// file**, not the compiler's CWD — see `specs/comptime-fs.md`.
// When to use: ship templates, prompts, JSON schemas, SQL queries, or
// shaders as string constants — no runtime fopen, no missing-file
// failures in production, no path resolution gymnastics.
use std::fs

let banner = comptime fs.read("07-embed-file.banner.txt")

print(banner)

// expected (once implemented):
//   Welcome to Zolo!
//   comptime makes constants free.

// You can pipe the result through other comptime methods, since the
// return is a normal comptime string.
let upper_banner = comptime {
  fs.read("07-embed-file.banner.txt").trim().to_upper()
}

print(upper_banner)
// expected (once implemented):
//   WELCOME TO ZOLO!
//   COMPTIME MAKES CONSTANTS FREE.
enespt-br