
Built-in functions are available everywhere without imports. `print`, `len`, `range`, type conversions like `str()` and `int()`, and a few others. The compiler knows their signatures natively, so they work without any setup.

## General

| **Function** | **Description** |
|----------|-------------|
| `print(value)` | Print to stdout |
| `input(prompt)` | Read line from stdin |
| `len(x)` | Length of string, list, dict, or set |
| `range(n)` | Integers 0 to n-1 |
| `range(start, stop)` | Integers start to stop-1 |
| `range(start, stop, step)` | Integers with step |
| `enumerate(iterable)` | List of `(index, element)` tuples |
| `str(x)` | Convert to string |
| `int(x)` | Convert to integer |
| `float(x)` | Convert to float |
| `bool(x)` | Convert to boolean |
| `abs(n)` | Absolute value |
| `min(a, b)` | Minimum |
| `max(a, b)` | Maximum |
| `type(x)` | Get type name as string |
| `isinstance(x, T)` | Check type |
| `chr(n)` | Integer to character |
| `ord(c)` | Character to integer |
| `sorted(list)` | Return sorted copy |
| `reversed(list)` | Return reversed copy |
| `sum(list)` | Sum of a `List[Int]` |
| `any(list)` | True if any element is truthy |
| `all(list)` | True if all elements are truthy |
| `time()` | Current time in seconds (Float) |

## Math

| **Function** | **Description** |
|----------|-------------|
| `sqrt(x)` | Square root |
| `pow(base, exp)` | Power |
| `floor(x)` | Round down |
| `ceil(x)` | Round up |
| `round(x)` | Round to nearest |
| `sin(x)`, `cos(x)`, `tan(x)` | Trigonometric |
| `asin(x)`, `acos(x)`, `atan(x)` | Inverse trig |
| `log(x)`, `log10(x)` | Logarithms |
| `exp(x)` | e^x |

## I/O

| **Function** | **Description** |
|----------|-------------|
| `fs.read_text(p)` | Read file contents as string (typed `ReadPath`) |
| `fs.write_text(p, data)` | Write string to file (typed `WritePath`) |
| `fs.exists(p)` | Check if path exists |
| `getenv(name)` | Get environment variable |
| `sleep(seconds)` | Sleep for given duration (Float) |

## Process execution

| **Function** | **Description** |
|----------|-------------|
| `process.run(args, cwd?, env?)` | Run a subprocess, returns `ProcessResult` |
| `process.cmd(program)` | Create a `Command` builder for fluent process construction |

```vary-snippet
import process

let result = process.run(["ls", "-la"])
print(result.stdout())

let out = process.cmd("echo").arg("hello").capture()
```

`ProcessResult` methods: `exit_code()` (Int), `stdout()` (Str), `stderr()` (Str), `ok()` (Bool), `require_ok()` (ProcessResult).

`Command` builder methods: `arg(value)`, `args(values)`, `with_cwd(path)`, `with_env(name, value)`, `run()`, `check()`, `capture()`.

`Command.run()` returns `Result[ProcessResult, ProcessError]`. Use `match` or `.unwrap()` to handle the result:

```vary-snippet
let result = process.cmd("git").arg("status").run()
match result {
    case Ok(pr) { print(pr.stdout()) }
    case Err(e) { print(f"Failed: {e.message()}") }
}
```

`ProcessError` methods: `kind()` (Str: `"not_found"`, `"permission_denied"`, `"timeout"`, `"io_error"`, `"start_failed"`), `message()` (Str).

## Clock and RNG

Typed abstractions for deterministic testing:

| **Function** | **Description** |
|----------|-------------|
| `Clock.real()` | Real-time clock |
| `Clock.fixed(epoch_ms)` | Clock with fixed time (for testing) |
| `clock.now_ms()` | Current time in milliseconds (Int) |
| `Rng.seeded(seed)` | Deterministic random number generator |
| `Rng.system()` | Non-deterministic RNG from system entropy |
| `rng.next_int(min, max)` | Random integer in range (Int) |

```vary
import time
import random

def main() {
    let clock = Clock.fixed(1000)
    print(clock.now_ms())

    let rng = Rng.seeded(42)
    print(rng.next_int(1, 6))
}
```

## Concurrency

| **Function** | **Description** |
|----------|-------------|
| `set_test_sequential(enabled)` | Run spawned tasks on the current thread for deterministic testing |
| `CancellationToken.create()` | Create a standalone cancellation token |
| `CancellationToken.current()` | Get the token for the current task group (`CancellationToken?`) |

See [Concurrency](/docs/concurrency/) for `task_group` blocks, timeouts, and cancellation.

## Static HTTP server

| **Function** | **Description** |
|----------|-------------|
| `http.serve(directory, port?, host?, spa?)` | Start a static file server (blocks until stopped) |

```vary-snippet
import http

http.serve("./public", port=3000)
```

Defaults: `port=8080`, `host="127.0.0.1"`, `spa=False`. SPA mode serves `index.html` for missing paths.

## File watching

| **Function** | **Description** |
|----------|-------------|
| `fs.watch(directory, recursive?, settle_ms?, ignore?)` | Create a persistent file watcher, returns `FileWatcher` |
| `fs.watch_once(directory, recursive?, settle_ms?, ignore?)` | Wait for a single batch of changes, returns `List[FileChange]` |

```vary-snippet
import fs

let watcher = fs.watch("./src")
let changes = watcher.next_batch(None)
for c in changes {
    print(f"{c.kind()} {c.path()}")
}
watcher.close()
```

`FileWatcher` methods: `next_batch(timeout_ms?)`, `close()`, `is_closed()`.

`FileChange` methods: `kind()` (Str: "created"/"modified"/"deleted"), `path()` (Str), `absolute_path()` (Str), `is_dir()` (Bool).

## JSON

```vary-snippet
let s = json_dumps({"name": "Alice", "age": 30})
let data = json_loads(s)
print(data["name"])     # Alice
```

`json_dumps()` works with strings, numbers, booleans, lists, and dicts. `json_loads()` returns untyped Vary values.

## Random

```vary
import random

random.seed(42)
let x = random.randint(1, 6)
let y = random.randrange(0, 10)
```

| **Function** | **Description** |
|----------|-------------|
| `random.randint(a, b)` | Random integer in `[a, b]` inclusive |
| `random.randrange(start, stop)` | Random integer in `[start, stop)` |
| `random.seed(n)` | Seed the generator |
