Part V · Complete Tooling, CLI & Standard Library Reference
Appendix B.1
Standard Library Reference: Core, CLI, Math, Text, Thompson NFA Regex & Streams
Complete AST-verified API reference for 28 foundational, text, regex, collection, and I/O stream modules
Foundational pure-Veko standard library modules (lib/), extracted directly from live AST signatures and module docstrings.
Module (use [...]) | Source File | Capabilities | Types | Functions |
|---|---|---|---|---|
bits | lib/bits.vk | Zero host capabilities | 1 | 28 |
buf | lib/buf.vk | Zero host capabilities | 3 | 34 |
cli | lib/cli.vk | Zero host capabilities | 4 | 6 |
coll | lib/coll.vk | Zero host capabilities | 5 | 29 |
datetime | lib/datetime.vk | ..clocks | 1 | 15 |
dialect | lib/dialect.vk | Zero host capabilities | 1 | 5 |
diff | lib/diff.vk | Zero host capabilities | 1 | 3 |
fmt | lib/fmt.vk | Zero host capabilities | 0 | 11 |
fs | lib/fs.vk | ..fs, ..clocks | 0 | 11 |
glob | lib/glob.vk | Zero host capabilities | 0 | 2 |
io/fs | lib/io/fs.vk | ..fs | 1 | 7 |
io/net | lib/io/net.vk | ..net | 1 | 15 |
io/open | lib/io/open.vk | ..net | 0 | 2 |
io | lib/io.vk | Zero host capabilities | 5 | 11 |
math | lib/math.vk | Zero host capabilities | 0 | 48 |
path | lib/path.vk | Zero host capabilities | 0 | 11 |
rand | lib/rand.vk | ..clocks | 1 | 12 |
regex | lib/regex.vk | Zero host capabilities | 4 | 5 |
retry | lib/retry.vk | ..clocks | 2 | 5 |
semver | lib/semver.vk | Zero host capabilities | 1 | 7 |
seq | lib/seq.vk | Zero host capabilities | 0 | 19 |
slog | lib/slog.vk | Zero host capabilities | 1 | 12 |
template | lib/template.vk | Zero host capabilities | 0 | 3 |
testing/fuzz | lib/testing/fuzz.vk | Zero host capabilities | 2 | 5 |
testing | lib/testing.vk | ..clocks | 2 | 10 |
text/re | lib/text/re.vk | Zero host capabilities | 3 | 7 |
text | lib/text.vk | Zero host capabilities | 0 | 21 |
utf8 | lib/utf8.vk | Zero host capabilities | 1 | 7 |
Module bits
Exported Structs & Interfaces
VarintVal:VarintVal = struct { value i64, next_off i64 }— Result of decoding a varint at a byte offset.
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
get-u24-be | get-u24-be = fn [b bytes, off i64] i64 | Reads an unsigned 24-bit big-endian integer from b at off. |
get-u24-le | get-u24-le = fn [b bytes, off i64] i64 | Reads an unsigned 24-bit little-endian integer from b at off. |
set-u24-be | set-u24-be = fn [mut b bytes, off i64, v i64] i64 | Writes an unsigned 24-bit big-endian integer into b at off. |
set-u24-le | set-u24-le = fn [mut b bytes, off i64, v i64] i64 | Writes an unsigned 24-bit little-endian integer into b at off. |
push-u24-be | push-u24-be = fn [mut b bytes, v i64] i64 | Appends an unsigned 24-bit big-endian integer to b, returning the new length. |
push-u24-le | push-u24-le = fn [mut b bytes, v i64] i64 | Appends an unsigned 24-bit little-endian integer to b, returning the new length. |
get-i16-le | get-i16-le = fn [b bytes, off i64] i64 | Reads a signed 16-bit little-endian integer from b at off. |
get-i16-be | get-i16-be = fn [b bytes, off i64] i64 | Reads a signed 16-bit big-endian integer from b at off. |
get-i32-le | get-i32-le = fn [b bytes, off i64] i64 | Reads a signed 32-bit little-endian integer from b at off. |
get-i32-be | get-i32-be = fn [b bytes, off i64] i64 | Reads a signed 32-bit big-endian integer from b at off. |
push-i16-le | push-i16-le = fn [mut b bytes, v i64] i64 | Appends a signed 16-bit little-endian integer to b. |
push-i16-be | push-i16-be = fn [mut b bytes, v i64] i64 | Appends a signed 16-bit big-endian integer to b. |
push-i32-le | push-i32-le = fn [mut b bytes, v i64] i64 | Appends a signed 32-bit little-endian integer to b. |
push-i32-be | push-i32-be = fn [mut b bytes, v i64] i64 | Appends a signed 32-bit big-endian integer to b. |
f64-to-bits | f64-to-bits = fn [x f64] i64 | Converts an IEEE-754 f64 value into its 64-bit integer bit pattern. |
bits-to-f64 | bits-to-f64 = fn [raw i64] f64 | Reconstructs an IEEE-754 f64 value from its 64-bit integer bit pattern. |
zigzag-encode | zigzag-encode = fn [n i64] i64 | Encodes a signed i64 into an unsigned ZigZag i64 bit pattern. |
zigzag-decode | zigzag-decode = fn [u i64] i64 | Decodes an unsigned ZigZag i64 back into a signed i64. |
push-varint-u64 | push-varint-u64 = fn [mut out bytes, v i64] i64 | Appends an unsigned LEB128 varint (64-bit) to out, returning the new length. |
read-varint-u64 | read-varint-u64 = fn [b bytes, off i64] VarintVal | Reads an unsigned LEB128 varint from b starting at off. |
crc32 | crc32 = fn [data bytes] i64 | Computes the IEEE 802.3 CRC-32 checksum (0xEDB88320 reflected polynomial). |
adler32 | adler32 = fn [data bytes] i64 | Computes the RFC 1950 Adler-32 checksum of data. |
fnv1a-64 | fnv1a-64 = fn [data bytes] i64 | Computes the 64-bit FNV-1a non-cryptographic hash of data. |
index-of | index-of = fn [hay bytes, needle bytes, start i64] i64 | Finds the first index of needle inside hay at or after start, or -1 if absent. |
starts-with? | starts-with? = fn [data bytes, prefix bytes] bool | Returns true if data starts with prefix. |
ends-with? | ends-with? = fn [data bytes, suffix bytes] bool | Returns true if data ends with suffix. |
xor-in-place! | xor-in-place! = fn [mut dst bytes, mask bytes] i64 | XORs mask into dst in-place across min(len dst, len mask) bytes. |
ct-eq? | ct-eq? = fn [a bytes, b bytes] bool | Constant-time equality comparison for equal-length byte buffers (returns false if lengths differ). |
Verified Doctest (bits/get-u24-be)
VEKO
use [bits]
mut b = bytes/with-cap 4
_ = bits/push-u24-be mut b 0x123456
if (bits/get-u24-be b 0) != 0x123456 [ err 'u24-be mismatch' ] else [ .ok ]Module buf
Exported Structs & Interfaces
ByteReader:ByteReader = struct { data bytes, pos i64 = ... }— Sequential cursor over an immutablebytesbuffer.ByteWriter:ByteWriter = struct { buf bytes }— Growable binary buffer builder for packet and file serialization.StringBuilder:StringBuilder = struct { buf bytes }— Growable UTF-8 string builder backed by a pre-allocatedbytesslab.
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
reader-new | reader-new = fn [data bytes] ByteReader | Creates a new ByteReader positioned at offset 0 of data. |
reader-remaining | reader-remaining = fn [r ByteReader] i64 | Returns the number of unread bytes remaining in r. |
reader-eof? | reader-eof? = fn [r ByteReader] bool | Returns true when r has reached the end of its buffer. |
reader-seek | reader-seek = fn [mut r ByteReader, off i64] i64 | Moves the cursor of r to absolute byte offset off. |
reader-skip | reader-skip = fn [mut r ByteReader, n i64] i64 | Advances the cursor of r by n bytes. |
read-u8 | read-u8 = fn [mut r ByteReader] i64 | Reads a single unsigned byte from r. |
read-u16-le | read-u16-le = fn [mut r ByteReader] i64 | Reads an unsigned 16-bit little-endian integer from r. |
read-u16-be | read-u16-be = fn [mut r ByteReader] i64 | Reads an unsigned 16-bit big-endian integer from r. |
read-u32-le | read-u32-le = fn [mut r ByteReader] i64 | Reads an unsigned 32-bit little-endian integer from r. |
read-u32-be | read-u32-be = fn [mut r ByteReader] i64 | Reads an unsigned 32-bit big-endian integer from r. |
read-i64-le | read-i64-le = fn [mut r ByteReader] i64 | Reads a 64-bit little-endian integer from r. |
read-i64-be | read-i64-be = fn [mut r ByteReader] i64 | Reads a 64-bit big-endian integer from r. |
read-bytes | read-bytes = fn [mut r ByteReader, n i64] bytes | Reads exactly n bytes from r. |
read-str | read-str = fn [mut r ByteReader, n i64] str | Reads n bytes from r and decodes them as a UTF-8 str. |
read-rest | read-rest = fn [mut r ByteReader] bytes | Reads all remaining unread bytes from r. |
read-until | read-until = fn [mut r ByteReader, delim i64] bytes | Reads bytes up to (but not including) delim, advancing past delim; returns err if not found. |
writer-new | writer-new = fn [cap i64] ByteWriter | Creates a new ByteWriter pre-allocated with cap bytes. |
writer-len | writer-len = fn [w ByteWriter] i64 | Returns the current byte length written into w. |
writer-bytes | writer-bytes = fn [w ByteWriter] bytes | Returns the accumulated bytes buffer from w. |
write-u8 | write-u8 = fn [mut w ByteWriter, v i64] i64 | Appends one byte to w. |
write-u16-le | write-u16-le = fn [mut w ByteWriter, v i64] i64 | Appends a 16-bit little-endian integer to w. |
write-u16-be | write-u16-be = fn [mut w ByteWriter, v i64] i64 | Appends a 16-bit big-endian integer to w. |
write-u32-le | write-u32-le = fn [mut w ByteWriter, v i64] i64 | Appends a 32-bit little-endian integer to w. |
write-u32-be | write-u32-be = fn [mut w ByteWriter, v i64] i64 | Appends a 32-bit big-endian integer to w. |
write-i64-le | write-i64-le = fn [mut w ByteWriter, v i64] i64 | Appends a 64-bit little-endian integer to w. |
write-i64-be | write-i64-be = fn [mut w ByteWriter, v i64] i64 | Appends a 64-bit big-endian integer to w. |
write-bytes | write-bytes = fn [mut w ByteWriter, data bytes] i64 | Appends a bytes slice to w. |
write-str | write-str = fn [mut w ByteWriter, s str] i64 | Appends a UTF-8 str to w. |
sb-new | sb-new = fn [cap i64] StringBuilder | Creates a new StringBuilder with initial capacity cap. |
sb-push | sb-push = fn [mut sb StringBuilder, s str] i64 | Appends s to sb. |
sb-push-line | sb-push-line = fn [mut sb StringBuilder, s str] i64 | Appends s followed by \n to sb. |
sb-push-byte | sb-push-byte = fn [mut sb StringBuilder, b i64] i64 | Appends a single byte b to sb. |
sb-len | sb-len = fn [sb StringBuilder] i64 | Returns the current byte length of sb. |
sb-build | sb-build = fn [sb StringBuilder] str | Returns the built UTF-8 string. |
Verified Doctest (buf/reader-new)
VEKO
use [buf]
mut w = buf/writer-new 16
_ = buf/write-u16-be mut w 0x0303
_ = buf/write-u32-le mut w 0x11223344
mut r = buf/reader-new (buf/writer-bytes w)
v1 = buf/read-u16-be mut r
v2 = buf/read-u32-le mut r
if v1 != 0x0303 or v2 != 0x11223344 or (not (buf/reader-eof? r)) [ err 'buf rw' ] else [ .ok ]Module cli
Exported Structs & Interfaces
FlagSpec:FlagSpec = struct { name str, short str = ..., kind enum = ..., required bool = ..., default_val any = ..., help str = ... }— Describes a single CLI flag (--name, optional-s, and value kind.bool,.i64,.str, or.list).CmdSpec:CmdSpec = struct { name str, summary str = ..., flags block[FlagSpec] = ..., min_args i64 = ... }— Describes a CLI subcommand and its command-specific flags.CliSpec:CliSpec = struct { name str, version str = ..., summary str = ..., flags block[FlagSpec] = ..., commands block[CmdSpec] = ... }— Top-level specification for a command-line application.CliResult:CliResult = struct { command str = ..., flags map = ..., args block[str] = ..., help_requested bool = ..., version_requested bool = ... }— Parsed command-line invocation produced bycli/parse.
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
parse | parse = fn [spec CliSpec, argv block[str]] CliResult | Parses argv according to spec, validating flag types, short clusters (-abc), --key=value syntax, subcommands, required flags, and -- positional separation. |
flag-str | flag-str = fn [res CliResult, name str, fallback str] str | Retrieves a string flag value from res, falling back to fallback. |
flag-i64 | flag-i64 = fn [res CliResult, name str, fallback i64] i64 | Retrieves an i64 flag value from res, falling back to fallback. |
flag-bool | flag-bool = fn [res CliResult, name str] bool | Retrieves a boolean flag value from res (defaults to false). |
flag-list | flag-list = fn [res CliResult, name str] block | Retrieves a repeatable .list flag value from res (defaults to []). |
render-help | render-help = fn [spec CliSpec] str | Renders a clean --help usage guide for spec. |
Verified Doctest (cli/parse)
VEKO
use [cli]
spec = cli/CliSpec {
name = 'demo'
flags = [
cli/FlagSpec { name = 'port', short = 'p', kind = .i64, default_val = 8080 }
cli/FlagSpec { name = 'verbose', short = 'v', kind = .bool, default_val = false }
]
}
res = cli/parse spec ['-v' '--port=9090' 'input.vk']
if (cli/flag-i64 res 'port' 0) != 9090 or (not (cli/flag-bool res 'verbose')) [
err 'cli/parse mismatch'
] else [ .ok ]Module coll
Exported Structs & Interfaces
Set:Set = struct { data map = ... }— Unordered set of scalar keys (str,i64, or.enum), backed by hybrid hashedmap.Ring:Ring = struct { buf block, cap i64, head i64 = ..., count i64 = ... }— Fixed-capacity O(1) FIFO ring buffer.Heap:Heap = struct { items block = ... }— Binary min-heap priority queue storing{ prio = i64, val = any }entries.Lru:Lru = struct { cap i64, data map = ..., order block[str] = ... }— Bounded Least-Recently-Used cache keyed bystr.Memo:Memo = struct { cache map = ..., hits i64 = ... }— Simple key-value memoization cache for pure functions.
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
set-new | set-new = fn [] Set | Creates a new empty Set. |
set-from | set-from = fn [xs block] Set | Creates a Set initialized with all elements of xs. |
set-add | set-add = fn [mut s Set, k any] i64 | Inserts k into s in-place. |
set-remove | set-remove = fn [mut s Set, k any] i64 | Removes k from s in-place. |
set-has? | set-has? = fn [s Set, k any] bool | Returns true if k is in s. |
set-len | set-len = fn [s Set] i64 | Returns the number of elements in s. |
set-items | set-items = fn [s Set] block | Returns all elements of s as a block. |
set-union | set-union = fn [a Set, b Set] Set | Returns the union a U b. |
set-intersect | set-intersect = fn [a Set, b Set] Set | Returns the intersection a /\ b. |
set-diff | set-diff = fn [a Set, b Set] Set | Returns the difference a \ b. |
ring-new | ring-new = fn [cap i64] Ring | Creates a new bounded Ring with capacity cap > 0. |
ring-len | ring-len = fn [r Ring] i64 | Number of items currently stored in r. |
ring-full? | ring-full? = fn [r Ring] bool | Returns true if r is at capacity. |
ring-empty? | ring-empty? = fn [r Ring] bool | Returns true if r is empty. |
ring-push | ring-push = fn [mut r Ring, val any] i64 | Appends val to the tail of r; returns err if full. |
ring-pop | ring-pop = fn [mut r Ring] any | Removes and returns the oldest item from r; returns err if empty. |
ring-peek | ring-peek = fn [r Ring] any | Returns the oldest item in r without removing it; returns err if empty. |
heap-new | heap-new = fn [] Heap | Creates a new empty min-Heap. |
heap-len | heap-len = fn [h Heap] i64 | Returns the number of entries in h. |
heap-push | heap-push = fn [mut h Heap, prio i64, val any] i64 | Pushes val with integer priority prio (smaller prio pops first). |
heap-peek | heap-peek = fn [h Heap] any | Returns the lowest-priority value without popping; returns err if empty. |
heap-pop | heap-pop = fn [mut h Heap] any | Pops and returns the value with the smallest priority; returns err if empty. |
lru-new | lru-new = fn [cap i64] Lru | Creates a new LRU cache holding at most cap > 0 entries. |
lru-has? | lru-has? = fn [c Lru, k str] bool | Returns true if k is currently cached in c. |
lru-len | lru-len = fn [c Lru] i64 | Returns the number of cached entries in c. |
lru-get | lru-get = fn [mut c Lru, k str] any | Looks up k in c, marking it most-recently-used; returns err if absent. |
lru-put | lru-put = fn [mut c Lru, k str, val any] i64 | Inserts or updates k -> val in c, evicting the least-recently-used key when full. |
memo-new | memo-new = fn [] Memo | Creates a new empty Memo cache. |
memo-call | memo-call = fn [mut m Memo, key str, compute fn[->any]] any | Returns cached value for key, or invokes (compute) once, caches the result, and returns it. |
Verified Doctest (coll/set-new)
VEKO
use [coll]
mut s = coll/set-new
coll/set-add mut s 'alpha'
coll/set-add mut s 'beta'
if (coll/set-len s) != 2 or (not (coll/set-has? s 'alpha')) [ err 'set' ] else [ .ok ]Module datetime
Exported Structs & Interfaces
DateTime:DateTime = struct { year i64, month i64, day i64, hour i64 = ..., minute i64 = ..., second i64 = ..., nanosecond i64 = ..., offset_sec i64 = ... }— Structured UTC / fixed-offset calendar date and time.
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
leap-year? | leap-year? = fn [year i64] bool | Returns true if year is a Gregorian leap year. |
days-in-month | days-in-month = fn [year i64, month i64] i64 | Returns the number of days in month (1..12) of year. |
from-unix | from-unix = fn [unix_sec i64, ns i64] DateTime | Converts a Unix epoch timestamp in seconds (with optional sub-second ns) to a UTC DateTime. |
from-unix-ns | from-unix-ns = fn [unix_ns i64] DateTime | Converts a Unix epoch timestamp in nanoseconds (e.g. from time/unix) to a UTC DateTime. |
now-utc | now-utc = fn [] DateTime | Returns the current UTC DateTime via time/unix (requires .clocks). |
to-unix | to-unix = fn [t DateTime] i64 | Converts t to Unix epoch seconds (accounting for t.offset_sec). |
to-unix-ns | to-unix-ns = fn [t DateTime] i64 | Converts t to Unix epoch nanoseconds. |
weekday | weekday = fn [t DateTime] i64 | Returns the ISO weekday (0 = Sunday, 1 = Monday, ..., 6 = Saturday). |
add-seconds | add-seconds = fn [t DateTime, delta_sec i64] DateTime | Returns a new DateTime shifted by delta_sec seconds, preserving t.offset_sec. |
add-days | add-days = fn [t DateTime, delta_days i64] DateTime | Returns a new DateTime shifted by delta_days days. |
with-offset | with-offset = fn [t DateTime, new_offset_sec i64] DateTime | Converts t to the same instant expressed at new_offset_sec east of UTC. |
diff-seconds | diff-seconds = fn [a DateTime, b DateTime] i64 | Returns the difference (a - b) in seconds. |
format-rfc3339 | format-rfc3339 = fn [t DateTime] str | Formats t as an RFC 3339 / ISO 8601 timestamp ('YYYY-MM-DDTHH:MM:SS[.fff][Z|+HH:MM]'). |
format-http | format-http = fn [t DateTime] str | Formats t in UTC as an HTTP IMF-fixdate (RFC 9110, e.g. 'Thu, 01 Jan 1970 00:00:00 GMT'). |
parse-rfc3339 | parse-rfc3339 = fn [s str] DateTime | Parses an RFC 3339 / ISO 8601 timestamp string into a DateTime. |
Verified Doctest (datetime/leap-year?)
VEKO
use [dt = datetime]
if (not (dt/leap-year? 2024)) or (dt/leap-year? 1900) or (not (dt/leap-year? 2000)) [ err 'leap' ] else [ .ok ]Module dialect
Exported Structs & Interfaces
Rule:Rule = struct { name str, pattern block, transform fn[map->any] }— Describes a single structural rewrite rule (pattern->transform fn[map -> any]).
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
rewrite-tree | rewrite-tree = fn [node any, visitor fn[any->any]] any | Recursively visits every node in a quoted/data block, applying visitor fn[any -> any] bottom-up to produce a transformed block tree. |
collect | collect = fn [tree any, pred fn[any->bool]] block | Collects every node inside tree for which (pred node) returns true. |
match-pattern | match-pattern = fn [pattern block, target block] map | Matches a flat or nested pattern against target block. String placeholders starting with '$' (e.g., '$proto', '$port') bind values into the returned map, and '*' matches any single element. Returns a bindings map on match, or err 'dialect/match-pattern: no match'. |
apply-rules | apply-rules = fn [clauses block[block], rules block[Rule]] block | Evaluates a sequence of dialect clauses (block[block]) against an ordered list of Rules, returning a block of transformed results (or err on the first unmatched clause). |
split-clauses | split-clauses = fn [items block, delim any] block | Splits a flat DSL token/item block into sub-blocks whenever delim appears. |
Verified Doctest (dialect/rewrite-tree)
VEKO
use [d = dialect]
tree = [1 [2 3] 4]
out = d/rewrite-tree tree fn [node] [
if (type-of node) == .i64_val [ node * 10 ] else [ node ]
]
if out != [10 [20 30] 40] [ err 'rewrite-tree' ] else [ .ok ]Module diff
Exported Structs & Interfaces
DiffLine:DiffLine = struct { op enum, text str, old_line i64, new_line i64 }— One entry in a computed line diff (op=.eq,.del, or.add).
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
diff-lines | diff-lines = fn [old_text str, new_text str] block[DiffLine] | Computes a minimal line-by-line diff between strings old_text and new_text. |
equal? | equal? = fn [ops block[DiffLine]] bool | Returns true if ops contains no additions or deletions. |
format-unified | format-unified = fn [old_name str, new_name str, old_text str, new_text str] str | Formats a unified diff string (--- old_name\n+++ new_name\n...) or '' when identical. |
Verified Doctest (diff/diff-lines)
VEKO
use [diff]
ops = diff/diff-lines 'a\nb\nc' 'a\nx\nc\nd'
if (diff/equal? ops) [ err 'diff equal' ] else [ .ok ]Module fmt
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
int-radix | int-radix = fn [n i64, base i64] str | Formats a signed integer n in the given base (2..36). |
pad-left | pad-left = fn [s str, width i64, pad_ch str] str | Pads s on the left with pad_ch (1-byte string) to reach width bytes. |
pad-right | pad-right = fn [s str, width i64, pad_ch str] str | Pads s on the right with pad_ch (1-byte string) to reach width bytes. |
hex | hex = fn [n i64, width i64] str | Formats a non-negative integer n as zero-padded lowercase hexadecimal of at least width chars. |
hex-bytes | hex-bytes = fn [data bytes] str | Formats a bytes buffer as a lowercase hexadecimal string. |
size | size = fn [n i64] str | Formats a byte count into a human-readable IEC size string (B, KiB, MiB, GiB, TiB). |
dur | dur = fn [ns i64] str | Formats a duration in nanoseconds into a readable unit string (ns, us, ms, s, m/s). |
format | format = fn [tpl str, args block] str | Formats tpl using positional placeholders ({0}, {1}, or auto-numbered {}). Double braces {{ and }} emit literal braces. |
template | template = fn [tpl str, vars map] str | Formats tpl using named {key} placeholders looked up in vars. Double braces {{ and }} emit literal braces. |
hexdump | hexdump = fn [data bytes, cols i64] str | Renders a canonical offset + hex + ASCII hexdump of data with cols bytes per row. |
table | table = fn [headers block[str], rows block] str | Renders a clean padded ASCII table from headers (block[str]) and rows (block[block[str]]). |
Verified Doctest (fmt/int-radix)
VEKO
use [fmt]
r1 = fmt/int-radix 255 16
r2 = fmt/int-radix -42 2
if r1 != 'ff' or r2 != '-101010' [ err 'fmt/int-radix mismatch' ] else [ .ok ]Module fs
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
exists? | exists? = fn [p str] bool | Returns true if p exists on the filesystem. |
dir? | dir? = fn [p str] bool | Returns true if p exists and is a directory. |
file? | file? = fn [p str] bool | Returns true if p exists and is a regular file (not a directory). |
mkdir-all | mkdir-all = fn [p str] enum | Recursively creates directory p and all missing parent directories (idempotent). |
remove-all | remove-all = fn [p str] enum | Recursively removes a file or directory tree (no-op if p does not exist). |
walk-dir | walk-dir = fn [root_dir str] block[str] | Recursively collects all file paths beneath root_dir. |
glob-dir | glob-dir = fn [root_dir str, pattern str] block[str] | Recursively collects all file paths beneath root_dir whose basename or relative path matches pattern. |
write-atomic | write-atomic = fn [dst_path str, data bytes] i64 | Atomically writes data to dst_path via a sibling temporary file, os/fsync, and os/rename. |
copy-file | copy-file = fn [src_path str, dst_path str] i64 | Copies src_path to dst_path atomically, returning the number of bytes copied. |
with-temp-dir | with-temp-dir = fn [prefix str, work fn[str->any]] any | Creates a unique temporary directory under os/temp-dir, invokes (work dir_path), and removes the directory via defer. |
list-entries | list-entries = fn [dir_path str] block[map] | Lists entries in dir_path as { name = str, is_dir = bool, size = i64 } maps (ready for ui/widgets/entries-from-list). |
Verified Doctest (fs/mkdir-all)
VEKO
use [fs]
base = str/join [(os/temp-dir) '/veko_fs_dt_mkdir'] ''
_ = fs/remove-all base
leaf = str/join [base '/a/b/c'] ''
_ = fs/mkdir-all leaf
ok = fs/dir? leaf
_ = fs/remove-all base
if not ok [ err 'mkdir-all' ] else [ .ok ]Module glob
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
match? | match? = fn [pattern str, target str] bool | Matches target against glob pattern (* matches non-/, ** matches across /, ? matches one non-/, [abc]/[a-z]/[!0-9] matches a character class). |
filter | filter = fn [pattern str, paths block[str]] block[str] | Filters paths returning all strings matching glob pattern. |
Verified Doctest (glob/match?)
VEKO
use [glob]
a = glob/match? 'src/**/*.vk' 'src/crypto/sha256.vk'
b = glob/match? 'lib/*.vk' 'lib/sub/a.vk'
c = glob/match? 'file_[0-9].txt' 'file_7.txt'
if (not a) or b or (not c) [ err 'glob/match?' ] else [ .ok ]Module io/fs
Exported Structs & Interfaces
FileStreamState:FileStreamState = struct { fd i64, path str, pos i64 = ... }— Backing state for a positioned file-backedio/Stream.
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
open-file | open-file = fn [path str, mode str] io/Stream | Opens path with mode ('r', 'w', 'rw', or 'a') and wraps the handle in an io/Stream. |
open-read | open-read = fn [path str] io/Stream | Opens path read-only as an io/Stream. |
open-write | open-write = fn [path str] io/Stream | Opens path for writing (creating or truncating) as an io/Stream. |
seek | seek = fn [mut s io/Stream, offset i64] i64 | Seeks a file-backed io/Stream s to absolute byte offset. |
sync | sync = fn [s io/Stream] enum | Flushes a file-backed io/Stream s to durable storage via os/fsync. |
pread-exact | pread-exact = fn [fd i64, offset i64, n i64] bytes | Reads exact n bytes at offset from raw positioned handle fd (errors on short read/EOF). |
pwrite-all | pwrite-all = fn [fd i64, offset i64, data bytes] i64 | Writes all bytes of data at offset to raw positioned handle fd. |
Verified Doctest (io/fs/open-file)
VEKO
use [io, ifs = io/fs]
p = 'dist/.doctest_io_fs.bin'
mut ws = ifs/open-file p 'w'
_ = io/write-all mut ws (bytes/from-str 'stream-disk-ok')
_ = io/close mut ws
mut rs = ifs/open-file p 'r'
got = io/read-all mut rs
_ = io/close mut rs
_ = os/remove/or p [ .ok ]
if (bytes/to-str got) != 'stream-disk-ok' [ err 'io/fs open-file' ] else [ .ok ]Module io/net
Exported Structs & Interfaces
TcpStreamState:TcpStreamState = struct { sock i64, peer str }— Backing state for a TCP socket-backedio/Stream.
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
tcp-stream | tcp-stream = fn [sock i64, peer str] io/Stream | Wraps an existing connected TCP socket handle sock in an io/Stream. |
resolve-ipv4 | resolve-ipv4 = fn [host str] block[str] | Resolves host to IPv4 addresses using .net-only primitives (localhost, numeric IPv4, net/resolve, and pure-Veko UDP DNS fallback). |
dial-tcp-timeout | dial-tcp-timeout = fn [host str, port i64, timeout dur] io/Stream | Dials a TCP connection to host:port with an enforced timeout duration and returns an io/Stream. |
dial-tcp | dial-tcp = fn [host str, port i64] io/Stream | Dials a TCP connection to host:port with a default 10s deadline and returns an io/Stream. |
stream-socket | stream-socket = fn [s io/Stream] i64 | Returns the underlying OS socket handle from a TCP-backed io/Stream. |
set-timeout | set-timeout = fn [s io/Stream, timeout dur] enum | Applies a read/write deadline timeout to a TCP-backed io/Stream. |
poll-streams | poll-streams = fn [streams block[io/Stream], timeout dur] block | Polls streams (block[io/Stream]) for readability up to timeout and returns indices of ready streams. |
set-nonblock | set-nonblock = fn [sock i64, enabled bool] enum | Toggles non-blocking mode (O_NONBLOCK / FIONBIO) on OS socket sock. |
listen-nonblock | listen-nonblock = fn [addr str] i64 | Binds a TCP listener on addr ('127.0.0.1:0') and enables non-blocking mode. |
dial-tcp-nonblock | dial-tcp-nonblock = fn [host str, port i64] i64 | Starts a non-blocking TCP connection to host:port (returns socket handle in connecting/connected state). |
sock-error | sock-error = fn [sock i64] i64 | Reads SO_ERROR on sock (returns 0 when healthy/connected, or non-zero OS error code). |
try-accept | try-accept = fn [ln i64] i64 | Non-blocking accept on listener ln: returns >= 0 client socket, -1 if would-block, or err. |
try-read-into | try-read-into = fn [sock i64, mut buf bytes, max_n i64] i64 | Non-blocking read appending up to max_n bytes into mut buf. Returns > 0 bytes read, 0 on clean peer EOF, -1 if would-block, or err. |
try-write | try-write = fn [sock i64, data bytes] i64 | Non-blocking write of data on sock: returns >= 0 bytes written, -1 if would-block, or err. |
try-write-from | try-write-from = fn [sock i64, data bytes, offset i64] i64 | Non-blocking write of data[offset..(len data)] on sock. |
Verified Doctest (io/net/tcp-stream)
VEKO
use [io, inet = io/net]
s = inet/tcp-stream 42 '127.0.0.1:8080'
if s.name != 'tcp://127.0.0.1:8080' or (inet/stream-socket s) != 42 [ err 'io/net' ] else [ .ok ]Module io/open
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
default-mux | default-mux = fn [] io/SchemeMux | Opens a SchemeMux pre-registered with mem://, file://, tcp://, tls://, http://, and https://. |
open | open = fn [uri str] io/Stream | Convenience wrapper that opens any mem://, file://, tcp://, tls://, http://, or https:// URI as an io/Stream. |
Verified Doctest (io/open/default-mux)
VEKO
use [io, iopen = io/open]
mux = iopen/default-mux
mut s = io/mux-open mux 'mem://hello-open'
got = io/read-all mut s
if (bytes/to-str got) != 'hello-open' [ err 'io/open mem' ] else [ .ok ]Module io
Exported Structs & Interfaces
ReadStep:ReadStep = struct { chunk bytes, state any }— Result of a single stream read step carrying the read chunk and updated ORO stream state.WriteStep:WriteStep = struct { written i64, state any }— Result of a single stream write step carrying bytes written and updated ORO stream state.Stream:Stream = struct { name str, closed bool = ..., state any = ..., read_step fn[any,i64->ReadStep], write_step fn[any,bytes->WriteStep], close_step fn[any->any] }— Generic byte stream supporting read, write, and close over ORO value state.MemState:MemState = struct { buf bytes, pos i64 = ... }— Internal backing state forio/mem-stream.SchemeMux:SchemeMux = struct { openers map[fn[str->Stream]] = ... }— URI scheme multiplexer mapping scheme names (such as'mem') to stream opener closures.
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
mem-stream | mem-stream = fn [initial bytes] Stream | Creates an in-memory read/write Stream initialized with initial bytes. |
read | read = fn [mut s Stream, max_n i64] bytes | Reads up to max_n bytes from s (returns empty bytes on EOF). |
write | write = fn [mut s Stream, data bytes] i64 | Writes data to s, returning the number of bytes written. |
close | close = fn [mut s Stream] enum | Closes s cleanly and returns .ok. |
read-all | read-all = fn [mut s Stream] bytes | Reads all remaining bytes from s until EOF. |
write-all | write-all = fn [mut s Stream, data bytes] i64 | Writes every byte of data to s, looping on short writes. |
copy | copy = fn [mut src Stream, mut dst Stream, chunk_size i64] i64 | Copies all remaining bytes from src into dst in chunk_size slices, returning total bytes copied. |
mux-new | mux-new = fn [] SchemeMux | Creates an empty SchemeMux. |
mux-register | mux-register = fn [mut mux SchemeMux, scheme str, opener fn[str->Stream]] i64 | Registers a scheme handler opener = fn [rest str] Stream [ ... ] under scheme. |
mux-default | mux-default = fn [] SchemeMux | Creates a default SchemeMux pre-registered with mem://<initial-utf8>. |
mux-open | mux-open = fn [mux SchemeMux, uri str] Stream | Opens a Stream for uri (e.g. 'mem://payload') by dispatching on the URI scheme before ://. |
Verified Doctest (io/mem-stream)
VEKO
use [io]
mut s = io/mem-stream (bytes/from-str 'hello ')
_ = io/write mut s (bytes/from-str 'veko')
all = io/read-all mut s
if (bytes/to-str all) != 'hello veko' [ err 'io mem-stream' ] else [ .ok ]Module math
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
pi | pi = fn [] f64 | Circle constant pi (folded at compile time). |
tau | tau = fn [] f64 | Full turn tau = 2 * pi (folded at compile time). |
e | e = fn [] f64 | Euler's number e (folded at compile time). |
ln2 | ln2 = fn [] f64 | Natural logarithm of 2 (folded at compile time). |
sqrt2 | sqrt2 = fn [] f64 | Square root of 2 (folded at compile time). |
i64-max | i64-max = fn [] i64 | Maximum signed 64-bit integer (2^63 - 1, folded at compile time). |
i64-min | i64-min = fn [] i64 | Minimum signed 64-bit integer (-2^63). |
abs-i64 | abs-i64 = fn [x i64] i64 | Absolute value of x (returns x for i64-min). |
min-i64 | min-i64 = fn [a i64, b i64] i64 | Smaller of two signed 64-bit integers. |
max-i64 | max-i64 = fn [a i64, b i64] i64 | Larger of two signed 64-bit integers. |
clamp-i64 | clamp-i64 = fn [x i64, lo i64, hi i64] i64 | Clamps x to the inclusive range [lo, hi]. |
add-checked | add-checked = fn [a i64, b i64] i64 | Checked 64-bit signed addition; returns err on overflow. |
sub-checked | sub-checked = fn [a i64, b i64] i64 | Checked 64-bit signed subtraction; returns err on overflow. |
mul-checked | mul-checked = fn [a i64, b i64] i64 | Checked 64-bit signed multiplication; returns err on overflow. |
add-sat | add-sat = fn [a i64, b i64] i64 | Saturating 64-bit signed addition (clamps at i64-min / i64-max). |
sub-sat | sub-sat = fn [a i64, b i64] i64 | Saturating 64-bit signed subtraction (clamps at i64-min / i64-max). |
gcd | gcd = fn [a i64, b i64] i64 | Greatest common divisor of a and b (non-negative). |
lcm | lcm = fn [a i64, b i64] i64 | Least common multiple of a and b (0 if either argument is 0). |
pow-i64 | pow-i64 = fn [base i64, exp i64] i64 | Integer exponentiation base ^ exp for exp >= 0. |
isqrt | isqrt = fn [n i64] i64 | Integer floor square root of n >= 0. |
popcount | popcount = fn [x i64] i64 | Counts the number of 1-bits in the 64-bit representation of x. |
clz | clz = fn [x i64] i64 | Counts leading zero bits in the 64-bit unsigned representation of x (64 for x == 0). |
ctz | ctz = fn [x i64] i64 | Counts trailing zero bits in the 64-bit representation of x (64 for x == 0). |
rotl64 | rotl64 = fn [x i64, r i64] i64 | Rotates a 64-bit word left by r bits (mod 64). |
rotr64 | rotr64 = fn [x i64, r i64] i64 | Rotates a 64-bit word right by r bits (mod 64). |
rotl32 | rotl32 = fn [x i64, r i64] i64 | Rotates a 32-bit unsigned word left by r bits (mod 32). |
rotr32 | rotr32 = fn [x i64, r i64] i64 | Rotates a 32-bit unsigned word right by r bits (mod 32). |
abs-f64 | abs-f64 = fn [x f64] f64 | Absolute value of x. |
min-f64 | min-f64 = fn [a f64, b f64] f64 | Smaller of two f64 values. |
max-f64 | max-f64 = fn [a f64, b f64] f64 | Larger of two f64 values. |
clamp-f64 | clamp-f64 = fn [x f64, lo f64, hi f64] f64 | Clamps x to [lo, hi]. |
isnan? | isnan? = fn [x f64] bool | Returns true if x is IEEE-754 NaN. |
isinf? | isinf? = fn [x f64] bool | Returns true if x is positive or negative infinity. |
trunc | trunc = fn [x f64] f64 | Truncates x toward zero. |
floor | floor = fn [x f64] f64 | Largest integer <= x as f64. |
ceil | ceil = fn [x f64] f64 | Smallest integer >= x as f64. |
round | round = fn [x f64] f64 | Rounds x to the nearest integer (halfway away from zero). |
sqrt | sqrt = fn [x f64] f64 | Double-precision square root lowered to hardware f64/sqrt (sqrtsd / f64.sqrt / fsqrt). |
exp | exp = fn [x f64] f64 | Exponential function e^x. |
ln | ln = fn [x f64] f64 | Natural logarithm ln(x) for x > 0. |
log2 | log2 = fn [x f64] f64 | Base-2 logarithm log2(x). |
log10 | log10 = fn [x f64] f64 | Base-10 logarithm log10(x). |
pow | pow = fn [base f64, exponent f64] f64 | Floating-point power base^exponent. |
sin | sin = fn [x f64] f64 | Sine of x in radians. |
cos | cos = fn [x f64] f64 | Cosine of x in radians. |
tan | tan = fn [x f64] f64 | Tangent of x in radians. |
atan | atan = fn [x f64] f64 | Arctangent of x in radians ([-pi/2, pi/2]). |
atan2 | atan2 = fn [y f64, x f64] f64 | Two-argument arctangent atan2(y, x) in radians ([-pi, pi]). |
Verified Doctest (math/clamp-i64)
VEKO
use [m = math]
if (m/clamp-i64 15 0 10) != 10 or (m/clamp-i64 -3 0 10) != 0 [ err 'clamp-i64' ] else [ .ok ]Module path
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
is-abs? | is-abs? = fn [p str] bool | Returns true if p is an absolute POSIX (/a/b) or Windows drive (C:/a/b) path. |
normalize | normalize = fn [p str] str | Lexically normalizes p, converting backslashes to /, collapsing duplicate slashes, and resolving . and .. segments cleanly. |
join | join = fn [a str, b str] str | Joins two path segments a and b and normalizes the result. |
join-all | join-all = fn [parts block[str]] str | Joins a block of path segments and normalizes the result. |
split-parts | split-parts = fn [p str] block[str] | Splits a normalized path into its non-empty path segments. |
dir | dir = fn [p str] str | Returns the parent directory portion of p. |
base | base = fn [p str] str | Returns the final filename component of p. |
ext | ext = fn [p str] str | Returns the file extension including the leading . (or '' if none). |
stem | stem = fn [p str] str | Returns the base filename without its final extension. |
with-ext | with-ext = fn [p str, new_ext str] str | Replaces (or appends) the file extension of p with new_ext (with or without leading .). |
confine | confine = fn [root str, rel str] str | Safely resolves rel inside root, returning err if rel is absolute or escapes root via ... |
Verified Doctest (path/normalize)
VEKO
use [path]
if (path/normalize 'a/b/../c/./d.vk') != 'a/c/d.vk' [ err 'normalize' ] else [ .ok ]Module rand
Exported Structs & Interfaces
Rng:Rng = struct { s0 i64, s1 i64, s2 i64, s3 i64 }— Deterministic xoshiro256++ pseudo-random number generator (256-bit state). Not for cryptographic keys; userand/csprng-bytesorrandom/bytesfor cryptography.
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
splitmix64-step | splitmix64-step = fn [seed i64] map | One SplitMix64 mixing step returning { val = i64, next_seed = i64 }. |
seed | seed = fn [seed_val i64] Rng | Seeds a deterministic xoshiro256++ Rng from a 64-bit seed via SplitMix64. |
next-u64 | next-u64 = fn [mut r Rng] i64 | Advances r using xoshiro256++ and returns the next 64-bit word. |
range | range = fn [mut r Rng, lo i64, hi i64] i64 | Returns a pseudo-random integer uniformly in [lo, hi) (lo < hi). |
f64-unit | f64-unit = fn [mut r Rng] f64 | Returns a uniform f64 in [0.0, 1.0) using 53 bits of precision. |
bytes-fill | bytes-fill = fn [mut r Rng, n i64] bytes | Produces n pseudo-random bytes from r. |
shuffle | shuffle = fn [mut r Rng, mut xs block] i64 | In-place Fisher-Yates shuffle of xs using r. |
choose | choose = fn [mut r Rng, xs block] any | Picks a random element from non-empty block xs. |
csprng-bytes | csprng-bytes = fn [n i64] bytes | Returns n cryptographically secure random bytes from the OS/hardware CSPRNG (random/bytes). |
uuid-v4 | uuid-v4 = fn [] str | Generates a random RFC 4122 Version 4 UUID string (xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx) using the OS/hardware CSPRNG. |
uuid-v7-at | uuid-v7-at = fn [unix_ms i64] str | Generates an RFC 9562 time-ordered Version 7 UUID string (xxxxxxxx-xxxx-7xxx-yxxx-xxxxxxxxxxxx) from a caller-provided 48-bit Unix millisecond timestamp unix_ms and OS CSPRNG entropy. |
uuid-v7 | uuid-v7 = fn [] str | Generates an RFC 9562 Version 7 UUID using the live UTC wall clock (time/unix) and OS CSPRNG. |
Verified Doctest (rand/seed)
VEKO
use [rand]
mut r1 = rand/seed 42
mut r2 = rand/seed 42
a = rand/next-u64 mut r1
b = rand/next-u64 mut r2
if a != b or a == 0 [ err 'rand/seed' ] else [ .ok ]Module regex
Exported Structs & Interfaces
NfaState:NfaState = struct { op i64, arg i64 = ..., out1 i64 = ..., out2 i64 = ... }— Single Thompson NFA state node.CharClass:CharClass = struct { negated bool = ..., ranges block = ... }— Character class specification (negated+ list of[lo, hi]byte ranges).Regex:Regex = struct { pattern str, states block[NfaState], classes block[CharClass], start i64 }— Compiled Thompson NFA regular expression.Match:Match = struct { text str, start i64, end i64 }— A matched substring span[start, end)within the input string.
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
compile | compile = fn [pattern str] Regex | Compiles a regular expression pattern into a linear-time Thompson NFA Regex. |
find | find = fn [rx Regex, input str] Match | Finds the first match of rx anywhere in input, or returns err 'regex/find: no match'. |
is-match? | is-match? = fn [rx Regex, input str] bool | Returns true if rx matches anywhere inside input. |
find-all | find-all = fn [rx Regex, input str] block[Match] | Finds all non-overlapping matches of rx in input. |
replace-all | replace-all = fn [rx Regex, input str, replacement str] str | Replaces every non-overlapping match of rx in input with replacement. |
Verified Doctest (regex/compile)
VEKO
use [re = regex]
rx = re/compile '^[a-z]+-[0-9]+$'
if (not (re/is-match? rx 'veko-10')) or (re/is-match? rx 'Veko-10') [ err 'regex' ] else [ .ok ]Module retry
Exported Structs & Interfaces
RetryOpts:RetryOpts = struct { max_attempts i64 = ..., base_delay dur = ..., max_delay dur = ..., jitter_pct i64 = ... }— Retry policy configuration with sensible defaults.RateLimiter:RateLimiter = struct { capacity i64, tokens i64, refill_per_sec i64, last_ns i64 }— Token-bucket rate limiter (monotonic clock backed viatime/now).
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
backoff-delay | backoff-delay = fn [opts RetryOpts, attempt i64] dur | Computes the deterministic exponential backoff delay (in dur) for 0-based attempt. |
run | run = fn [opts RetryOpts, action fn[i64->any]] any | Executes action (fn [attempt i64] any) up to opts.max_attempts times until it returns a non-err result. |
limiter-new | limiter-new = fn [capacity i64, refill_per_sec i64] RateLimiter | Creates a new full token-bucket RateLimiter with capacity burst tokens refilling at refill_per_sec. |
allow-at? | allow-at? = fn [mut rl RateLimiter, cost i64, now_ns i64] bool | Attempts to consume cost tokens at timestamp now_ns, returning true if allowed. |
allow? | allow? = fn [mut rl RateLimiter, cost i64] bool | Attempts to consume cost tokens using the current monotonic clock (time/now). |
Verified Doctest (retry/backoff-delay)
VEKO
use [retry]
opts = retry/RetryOpts { base_delay = 50ms, max_delay = 300ms, jitter_pct = 0 }
if (retry/backoff-delay opts 0) != 50ms or (retry/backoff-delay opts 2) != 200ms or (retry/backoff-delay opts 4) != 300ms [
err 'backoff'
] else [ .ok ]Module semver
Exported Structs & Interfaces
SemVer:SemVer = struct { major i64, minor i64, patch i64, pre str = ..., build str = ... }— Structured SemVer 2.0.0 version (major.minor.patch[-pre][+build]).
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
parse | parse = fn [raw_s str] SemVer | Parses a SemVer 2.0.0 string (accepts optional leading 'v'). |
format | format = fn [v SemVer] str | Formats a SemVer back into canonical 'MAJOR.MINOR.PATCH[-pre][+build]'. |
compare | compare = fn [a SemVer, b SemVer] i64 | Compares two SemVer values per SemVer 2.0.0 precedence (-1, 0, or 1; ignores +build). |
bump-major | bump-major = fn [v SemVer] SemVer | Exported semver/bump-major operation. |
bump-minor | bump-minor = fn [v SemVer] SemVer | Exported semver/bump-minor operation. |
bump-patch | bump-patch = fn [v SemVer] SemVer | Exported semver/bump-patch operation. |
satisfies? | satisfies? = fn [v SemVer, constraint str] bool | Returns true if v satisfies a comma-separated SemVer constraint (e.g. '^1.2.0', '~1.2.3', '>=1.0.0, <2.0.0'). |
Verified Doctest (semver/parse)
VEKO
use [sv = semver]
v = sv/parse 'v1.4.2-rc.1+build.9'
if v.major != 1 or v.minor != 4 or v.patch != 2 or v.pre != 'rc.1' or v.build != 'build.9' [
err 'semver parse'
] else [ .ok ]Module seq
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
reverse | reverse = fn [xs block] block | Returns a new block containing the elements of xs in reverse order. |
take | take = fn [xs block, k i64] block | Returns the first k elements of xs (clamped to [0, len xs]). |
drop | drop = fn [xs block, k i64] block | Drops the first k elements of xs and returns the remainder. |
fold | fold = fn [xs block, init any, step fn[any,any->any]] any | Left-folds xs starting from init using step = fn [acc, elem] [ ... ]. |
any? | any? = fn [xs block, pred fn[any->bool]] bool | Returns true if pred holds for at least one element in xs. |
all? | all? = fn [xs block, pred fn[any->bool]] bool | Returns true if pred holds for every element in xs. |
find | find = fn [xs block, pred fn[any->bool]] any | Returns the first element matching pred, or err 'seq/find: not found' (combine with /or). |
partition | partition = fn [xs block, pred fn[any->bool]] map | Splits xs into { yes = [...], no = [...] } according to pred. |
unique | unique = fn [xs block] block | Removes duplicate scalar/hashable elements from xs, preserving first-seen order. |
chunk | chunk = fn [xs block, size i64] block | Splits xs into consecutive chunks of length size (last chunk may be shorter). |
zip | zip = fn [a block, b block] block | Zips two blocks a and b into pairs [ [a0 b0] [a1 b1] ... ] up to min(len a, len b). |
enumerate | enumerate = fn [xs block] block | Produces [ [0 xs[0]] [1 xs[1]] ... ]. |
flatten | flatten = fn [xs block] block | Flattens one level of nested blocks into a single block. |
group-by | group-by = fn [xs block, key_fn fn[any->str]] map | Groups elements of xs into a map keyed by (key-fn elem). |
count-by | count-by = fn [xs block, key_fn fn[any->str]] map | Counts elements of xs per key produced by (key-fn elem). |
range-seq | range-seq = fn [start i64, stop i64, step i64] block[i64] | Generates an integer sequence [start, start + step, ...] stopping before stop. |
sort-by | sort-by = fn [xs block, cmp fn[any,any->i64]] block | Stable O(N log N) merge sort using comparator cmp = fn [a, b] i64 [ ... ] (< 0, 0, > 0). |
sort | sort = fn [xs block] block | Stable O(N log N) ascending sort for ordered scalars (i64, f64, or str). |
binary-search | binary-search = fn [xs block, target any] i64 | Binary search on a sorted block xs; returns index >= 0 if found or -1 otherwise. |
Verified Doctest (seq/reverse)
VEKO
use [seq]
if (seq/reverse [1 2 3]) != [3 2 1] [ err 'reverse' ] else [ .ok ]Module slog
Exported Structs & Interfaces
Logger:Logger = struct { level enum = ..., format enum = ..., fields map = ..., use_clock bool = ... }— Immutable structured logger configuration (clone & extend cleanly withwith-level/with-fields).
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
new-json | new-json = fn [min_level enum] Logger | Creates a JSON structured logger with the given minimum level (.debug, .info, .warn, .error). |
new-kv | new-kv = fn [min_level enum] Logger | Creates a human-readable key=value (kv) structured logger with the given minimum level. |
with-level | with-level = fn [lg Logger, min_level enum] Logger | Returns a child logger with an updated minimum log level. |
with-fields | with-fields = fn [lg Logger, extra map] Logger | Returns a child logger with additional contextual key/value fields merged in. |
enabled? | enabled? = fn [lg Logger, lvl enum] bool | Returns true if lvl meets or exceeds lg.level. |
format-line | format-line = fn [lg Logger, lvl enum, msg str, extra map] str | Formats a single structured log line (without emitting I/O — ideal for testing and custom sinks). |
emit | emit = fn [lg Logger, lvl enum, msg str, extra map] enum | Emits a structured log line to os/stderr if lvl is enabled on lg. |
emit-stream | emit-stream = fn [lg Logger, mut stream io/Stream, lvl enum, msg str, extra map] enum | Emits a structured log line to any io/Stream if lvl is enabled on lg. |
debug | debug = fn [lg Logger, msg str, extra map] enum | Convenience level emitters targeting os/stderr. |
info | info = fn [lg Logger, msg str, extra map] enum | Exported slog/info operation. |
warn | warn = fn [lg Logger, msg str, extra map] enum | Exported slog/warn operation. |
error | error = fn [lg Logger, msg str, extra map] enum | Exported slog/error operation. |
Verified Doctest (slog/format-line)
VEKO
use [slog]
lg = (slog/new-kv .debug) \ struct/with { use_clock = false } \ slog/with-fields { svc = 'api' }
line = slog/format-line lg .info 'ready' { port = 8080 }
if (not (str/contains? line 'level=INFO')) or (not (str/contains? line 'svc=api')) or (not (str/contains? line 'port=8080')) [
err 'slog format'
] else [ .ok ]Module template
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
escape-html | escape-html = fn [s str] str | Escapes HTML entities (&, <, >, ", '). |
render-html | render-html = fn [tpl str, ctx map] str | Renders tpl against ctx with automatic HTML escaping on {{ expr }} ({{{ raw }}} opts out). |
render-text | render-text = fn [tpl str, ctx map] str | Renders tpl against ctx as plain text (no HTML escaping). |
Verified Doctest (template/render-html)
VEKO
use [tpl = template]
out = tpl/render-html '<h1>{{ user.name }}</h1>{{#if admin}}<ul>{{#each tags}}<li>{{ . }}</li>{{/each}}</ul>{{/if}}' { user = { name = '<Ada>' }, admin = true, tags = ['oro' 'pqc'] }
if out != '<h1><Ada></h1><ul><li>oro</li><li>pqc</li></ul>' [ err 'template html' ] else [ .ok ]Module testing/fuzz
Exported Structs & Interfaces
FuzzConfig:FuzzConfig = struct { seed i64 = ..., runs i64 = ..., max_len i64 = ... }— Configuration for a deterministic fuzzing campaign.FuzzResult:FuzzResult = struct { ok bool = ..., runs i64 = ..., seed i64 = ..., failing_input any = ..., shrunk_input any = ..., shrink_steps i64 = ..., failure_msg str = ... }— Outcome of a fuzzing run, including the minimal delta-debugged counterexample on failure.
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
next-u64 | next-u64 = fn [state i64] StepU64 | Advances a 64-bit SplitMix64 state and returns StepU64 { state, val }. |
fuzz-bytes | fuzz-bytes = fn [cfg FuzzConfig, prop fn[bytes->any]] FuzzResult | Fuzzes prop over boundary byte vectors and cfg.runs pseudo-random bytes slices, shrinking any failing input to its minimal reproducing byte sequence. |
fuzz-str | fuzz-str = fn [cfg FuzzConfig, prop fn[str->any]] FuzzResult | Fuzzes prop over boundary strings and cfg.runs valid UTF-8 / delimiter strings, shrinking any failure down to the minimal failing UTF-8 string. |
fuzz-block | fuzz-block = fn [cfg FuzzConfig, prop fn[block->any]] FuzzResult | Fuzzes prop over structured homoiconic Veko blocks (i64, str, bool, .enum, and nested [ ... ] sub-blocks) and shrinks any failure to the minimal failing block. |
assert-fuzz | assert-fuzz = fn [res FuzzResult, label str] any | Returns .ok if res.ok == true, or a formatted err describing the seed and minimal counterexample. |
Verified Doctest (testing/fuzz/fuzz-bytes)
VEKO
use [fz = testing/fuzz]
cfg = fz/FuzzConfig { seed = 42, runs = 80, max_len = 32 }
ok_res = fz/fuzz-bytes cfg fn [b bytes] any [ (len b) <= 32 ]
if not ok_res.ok [ return (err 'expected ok_res to pass') ]
// Plant a bug triggered whenever consecutive bytes [0xfe 0xff] or byte >= 200 appear
bad = fz/fuzz-bytes cfg fn [b bytes] any [
mut i = 0
while i < (len b) [
if b[i] >= 200 [ return (err 'high byte boom') ]
i = i + 1
]
true
]
if bad.ok or (len bad.shrunk_input) != 1 [ err 'expected shrunk 1-byte reproducer' ] else [ .ok ]Module testing
Exported Structs & Interfaces
Suite:Suite = struct { name str, passed i64 = ..., failed i64 = ..., failures block[str] = ... }— Mutable test suite accumulator tracking pass/fail counts and failure diagnostics.BenchResult:BenchResult = struct { name str, iters i64, total_ns i64, ns_per_op i64 }— Timing result returned bytesting/bench.
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
new | new = fn [name str] Suite | Creates a new empty test Suite with the given name. |
ok | ok = fn [mut s Suite, cond bool, label str] bool | Asserts that cond is true. |
eq | eq = fn [mut s Suite, actual any, expected any, label str] bool | Asserts that actual == expected. |
neq | neq = fn [mut s Suite, actual any, unexpected any, label str] bool | Asserts that actual != unexpected. |
is-err | is-err = fn [mut s Suite, val any, label str] bool | Asserts that val is a Veko err. |
is-ok | is-ok = fn [mut s Suite, val any, label str] bool | Asserts that val is not a Veko err. |
approx | approx = fn [mut s Suite, actual f64, expected f64, eps f64, label str] bool | Asserts that two floats are within eps (|actual - expected| <= eps). |
finish | finish = fn [s Suite] i64 | Finalizes a Suite, returning 0 when all assertions passed or an err summarizing failures. |
report | report = fn [s Suite] i64 | Prints a compact single-line summary for s and returns finish s. |
bench | bench = fn [name str, iters i64, work fn[->any]] BenchResult | Executes work iters times and returns monotonic timing measurements (BenchResult). |
Verified Doctest (testing/new)
VEKO
use [t = testing]
mut s = t/new 'math-smoke'
_ = t/eq mut s (2 + 2) 4 'addition'
r = t/finish s
if err? r [ r ] else [ .ok ]Module text/re
Exported Structs & Interfaces
NfaInst:NfaInst = struct { op i64, ch i64 = ..., out i64 = ..., out1 i64 = ..., cset bytes = ..., neg bool = ... }— Single compiled Thompson NFA instruction.Regex:Regex = struct { pattern str, insts block[NfaInst], start_pc i64 }— Compiled regular expression automaton.Match:Match = struct { start i64, end i64, text str }— Byte-span match result (start..endslice of the input string).
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
compile | compile = fn [pattern str] Regex | Compiles pattern into a linear-time Regex NFA (returns err on invalid syntax; combine with /or). |
is-match? | is-match? = fn [rx Regex, text str] bool | Returns true if rx matches anywhere inside text. |
match? | match? = fn [pattern str, text str] bool | Convenience one-shot match test compiling pattern and testing text. |
find | find = fn [rx Regex, text str] Match | Finds the leftmost match of rx in text, or returns err if not found (combine with /or). |
find-all | find-all = fn [rx Regex, text str] block[Match] | Finds all non-overlapping matches of rx in text. |
replace-all | replace-all = fn [rx Regex, text str, replacement str] str | Replaces all non-overlapping matches of rx in text with replacement. |
split | split = fn [rx Regex, text str] block[str] | Splits text around non-overlapping non-empty matches of rx. |
Verified Doctest (text/re/compile)
VEKO
use [re = text/re]
rx = re/compile 'v[0-9]+\\.[0-9]+'
ms = re/find-all rx 'release v1.0 and v2.14 ready'
if (len ms) != 2 or ms[0].text != 'v1.0' or ms[1].text != 'v2.14' [ err 're find-all' ] else [ .ok ]Module text
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
starts-with? | starts-with? = fn [s str, pfx str] bool | Returns true if s starts with pfx. |
ends-with? | ends-with? = fn [s str, sfx str] bool | Returns true if s ends with sfx. |
contains? | contains? = fn [s str, needle str] bool | Returns true if s contains needle. |
index-of | index-of = fn [s str, needle str, start i64] i64 | Finds the first byte index of needle in s starting at start, or -1 if absent. |
last-index-of | last-index-of = fn [s str, needle str] i64 | Finds the last byte index of needle in s, or -1 if absent. |
replace | replace = fn [s str, old_s str, new_s str] str | Replaces the first occurrence of old_s in s with new_s. |
replace-all | replace-all = fn [s str, old_s str, new_s str] str | Replaces every non-overlapping occurrence of old_s in s with new_s. |
repeat | repeat = fn [s str, count i64] str | Repeats s count times ('' if count <= 0). |
trim-prefix | trim-prefix = fn [s str, pfx str] str | Strips pfx from the start of s if present. |
trim-suffix | trim-suffix = fn [s str, sfx str] str | Strips sfx from the end of s if present. |
lines | lines = fn [s str] block[str] | Splits s into lines, handling both \n and \r\n. |
ascii-space? | ascii-space? = fn [b i64] bool | Returns true if ASCII byte b is whitespace ( , \t, \r, \n). |
ascii-alpha? | ascii-alpha? = fn [b i64] bool | Returns true if ASCII byte b is an ASCII letter (A..Z or a..z). |
ascii-digit? | ascii-digit? = fn [b i64] bool | Returns true if ASCII byte b is an ASCII decimal digit (0..9). |
ascii-alnum? | ascii-alnum? = fn [b i64] bool | Returns true if ASCII byte b is alphanumeric (A..Z, a..z, 0..9). |
ascii-hex? | ascii-hex? = fn [b i64] bool | Returns true if ASCII byte b is a hexadecimal digit (0..9, a..f, A..F). |
words | words = fn [s str] block[str] | Splits s on contiguous ASCII whitespace into non-empty words. |
slugify | slugify = fn [s str] str | Converts s into a lowercase URL-safe ASCII slug ('Hello, Veko 1.0!' -> 'hello-veko-1-0'). |
utf8-len | utf8-len = fn [s str] i64 | Counts Unicode code points in a UTF-8 string s. |
utf8-codepoints | utf8-codepoints = fn [s str] block[i64] | Decodes a UTF-8 string into a block[i64] of Unicode scalar code points. |
utf8-from-codepoints | utf8-from-codepoints = fn [cps block[i64]] str | Encodes a block[i64] of Unicode code points into a UTF-8 str. |
Verified Doctest (text/starts-with?)
VEKO
use [text]
if (not (text/starts-with? 'veko-1.0' 'veko')) or (text/starts-with? 'hi' 'hello') [ err 'starts-with' ] else [ .ok ]Module utf8
Exported Structs & Interfaces
RuneStep:RuneStep = struct { codepoint i64, width i64 }— Decoded Unicode codepoint and the number of UTF-8 bytes consumed (1..4).
Exported Functions
| Symbol | Signature | Description |
|---|---|---|
decode-rune | decode-rune = fn [raw bytes, off i64] RuneStep | Decodes one UTF-8 codepoint from raw starting at byte offset off. Rejects overlong encodings, UTF-16 surrogates (0xD800..0xDFFF), and codepoints > 0x10FFFF. |
encode-rune | encode-rune = fn [cp i64] bytes | Encodes a single Unicode scalar value cp into 1..4 UTF-8 bytes. |
valid? | valid? = fn [raw bytes] bool | Returns true if raw consists exclusively of valid RFC 3629 UTF-8 codepoints. |
rune-count | rune-count = fn [s str] i64 | Returns the number of Unicode scalar values (runes) in UTF-8 string s. |
runes | runes = fn [s str] block[i64] | Decodes UTF-8 string s into a block[i64] of Unicode codepoints. |
from-runes | from-runes = fn [cps block[i64]] str | Encodes a block[i64] of Unicode codepoints back into a UTF-8 string. |
rune-slice | rune-slice = fn [s str, start i64, end_idx i64] str | Slices string s safely by rune indices [start..end_idx) without ever splitting multi-byte codepoints. |
Verified Doctest (utf8/decode-rune)
VEKO
use [utf8]
b = utf8/encode-rune 0x03BB // Greek lambda
st = utf8/decode-rune b 0
if st.codepoint != 0x03BB or st.width != 2 [ err 'decode-rune' ] else [ .ok ]