Standard Library

IRIS ships with a standard library of 12 modules covering common operations. All are implemented as .iris files built on primitive opcodes.

Math

stdlib/math.iris – Trigonometric, logarithmic, and utility functions built on opcodes 0xD80xE3.

-- Trigonometric
sin x    cos x    tan x

-- Logarithmic
log x    log10 x    log2 x    exp x

-- Utilities
sqrt x    pow x y    floor x    ceil x    round x
clamp x lo hi    lerp a b t    sigmoid x    tanh x

-- Distance
dist2d x1 y1 x2 y2

-- Constants
pi    e

-- Random
rand_int min max    rand_float

-- Conversions
to_radians deg    to_degrees rad

Collections

stdlib/list_ops.iris – List operations built on fold and list primitives.

-- Access
head xs    tail xs    last xs    init xs    nth xs i

-- Transform
append xs ys    concat xss    reverse xs    flatten xss

-- Slice
take xs n    drop xs n

-- Ordering
sort xs    dedup xs

-- Generate
range start end

-- Aggregate
length xs    list_sum xs    list_product xs

Maps

stdlib/map_ops.iris – Key-value operations.

map_new              -- Create empty map
map_insert m k v     -- Insert key-value pair
map_get m k          -- Lookup by key
map_remove m k       -- Remove a key
map_contains m k     -- Check key existence
map_keys m           -- List all keys
map_values m         -- List all values
map_size m           -- Number of entries
map_merge m1 m2      -- Merge two maps

Sets

stdlib/set_ops.iris – Sets implemented as sorted, deduplicated tuples. Not primitive opcodes – built from list_sort, list_dedup, filter, and fold.

set_empty            -- Empty set: ()
set_from_list xs     -- Create set from list (sort + dedup)
set_insert s x       -- Add element
set_contains s x     -- Check membership (returns 1 or 0)
set_remove s x       -- Remove element
set_union a b        -- Union
set_intersect a b    -- Intersection
set_diff a b         -- Difference (elements in a but not b)
set_size s           -- Cardinality
set_is_subset a b    -- All elements of a are in b (returns 1 or 0)

Strings

stdlib/string_ops.iris + stdlib/string_utils.iris – 17 string primitives plus utilities.

-- Core
str_len s    str_slice s start end    str_concat a b
str_contains s sub    str_split s delim    str_replace s old new
str_chars s    str_trim s

-- Utilities
reverse s    repeat s n    pad_left s n c    pad_right s n c
is_empty s    is_blank s    index_of s sub    count_occurrences s sub
str_starts_with s prefix    str_ends_with s suffix
str_to_upper s    str_to_lower s

File I/O

stdlib/file_ops.iris – File and directory operations.

let fd = file_open path mode    -- mode: "r", "w", "a"
let data = file_read_bytes fd n
file_write_bytes fd data
file_close fd
let info = file_stat path       -- Returns (size, modified_time)
let entries = dir_list path

Paths

stdlib/path_ops.iris – Path manipulation.

path_join a b        -- Join path components
path_dirname p       -- Directory part
path_basename p      -- File name part
path_extension p     -- File extension
path_is_absolute p   -- Check if absolute
path_normalize p     -- Normalize path

Time

stdlib/time_ops.iris – Time operations.

let now = clock_ns       -- Current time in nanoseconds
sleep_ms duration        -- Sleep for duration milliseconds

HTTP

stdlib/http_client.iris + stdlib/http_server.iris – HTTP built entirely on TCP primitives.

Client

-- Simple GET
let response = http_get "example.com" 80 "/api/data"

-- POST with body
let response = http_post "example.com" 80 "/api" body

-- Parsed responses (status_code, headers, body)
let (status, headers, body) = http_get_parsed host port path

-- Convenience
let body = http_get_body host port path
let status = http_status raw_response
let value = http_get_header raw_response "Content-Type"

Server

let server = tcp_listen "0.0.0.0" 8080
let conn = tcp_accept server
let request = tcp_read conn 65536
tcp_write conn response
tcp_close conn

Data Access

stdlib/data.iris – Tuple and list access.

let val = tuple_get obj key      -- Get field from tuple by key
let len = list_len xs            -- Length of a list

Threading

Threading primitives for concurrent programs.

-- Spawn and join
let handle = thread_spawn fn
let result = thread_join handle

-- Atomics
let val = atomic_read ref
atomic_write ref val
let old = atomic_swap ref new_val
atomic_add ref delta

-- Reader-writer locks
rwlock_read lock
rwlock_write lock
rwlock_release lock

Lazy Lists

stdlib/lazy.iris – Lazy infinite stream combinators built on thunk primitives.

-- Generators
naturals n           -- Infinite natural numbers starting from n
fibs                 -- Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, ...
repeat x             -- Infinite stream of constant value x
countdown n          -- Finite stream: n, n-1, ..., 1
powers_of_2          -- Powers of 2: 1, 2, 4, 8, 16, ...

-- Combinators
take n xs            -- Materialize first n elements as a tuple
lmap f xs            -- Lazy map: apply f to each element (lazy)

-- Derived
sum_first_n n        -- Sum of first n natural numbers

Primitives

These built-in primitives power the lazy list module:

lazy_unfold f seed   -- Create lazy stream from step function and seed
lazy_take n stream   -- Force first n elements into a tuple
lazy_map f stream    -- Transform each element lazily
thunk_force stream   -- Step once: returns (element, next_thunk) or ()

Higher-Order Primitives

Built-in higher-order operations available everywhere (primitive opcodes, no import required):

fold init f xs       -- Left fold (catamorphism)
map f xs             -- Transform each element
filter pred xs       -- Keep matching elements
zip xs ys            -- Pair elements
concat xs ys         -- Concatenate sequences
reverse xs           -- Reverse order

List operations (also primitive opcodes):

list_take xs n       -- First n elements
list_drop xs n       -- Skip n elements
list_sort xs         -- Sort ascending (integer comparison)
list_nth xs i        -- Element at index i
list_append xs ys    -- Concatenate two lists
list_range start end -- Generate range [start, end)

Note: sort_by (with comparator function), group_by, and flat_map are not built-in primitives. Implement them using fold and list_sort.