Standard Library

Aria's standard library is organized into two tiers. The design philosophy: the 90% case should be one function call.

Tier 0: Built-in (No Import Needed)

These are available everywhere without any use statement:

Output

println("hello")          // print with newline
print("no newline")       // print without newline

Lists

nums := [1, 2, 3, 4, 5]
nums.len()                          // 5
nums.map(fn(x) => x * 2)           // [2, 4, 6, 8, 10]
nums.filter(fn(x) => x > 3)        // [4, 5]
nums.fold(0, fn(a, b) => a + b)    // 15
nums.sort()                         // [1, 2, 3, 4, 5]
nums.reverse()                      // [5, 4, 3, 2, 1]
nums.enumerate()                    // [(0,1), (1,2), ...]
nums.contains(3)                    // true
nums.append(6)                      // [1, 2, 3, 4, 5, 6]
nums.join(", ")                     // "1, 2, 3, 4, 5"

Maps

m := Map()
m.set("a", 1)
m.set("b", 2)
m.get("a")         // 1
m.has("a")         // true
m.len()            // 2
m.keys()           // ["a", "b"]

Sets

s := Set()
s.add(1)
s.add(2)
s.add(3)
s.contains(2)      // true
s.remove(1)
s.len()            // 2
s.values()         // returns array

Tuples

pair := (42, "hello")
pair.0              // 42
pair.1              // "hello"
(a, b) := pair      // destructuring

Option and Result

type Option[T] = Some(T) | None
type Result[T, E] = Ok(T) | Err(E)

// Sugar: T? means Option[T]
// Sugar: T ! E means Result[T, E]

Strings

s := "hello, world"
s.len()              // byte length
s.split(",")         // ["hello", " world"]
s.trim()             // strip whitespace
s.contains("world")  // true
s.replace("o", "0")  // "hell0, w0rld"
s.toUpper()          // "HELLO, WORLD"
s.toLower()          // "hello, world"
s[2..5]              // "llo" (zero-copy slice)

Ranges

0..10     // exclusive: 0 to 9
0..=10    // inclusive: 0 to 10

Tier 1: Core Modules (One-Word Import)

use io, net, json, db, time, crypto, log, math

io — File I/O

use io

content := io.readFile("data.txt")?
io.writeFile("out.txt", content)?

file := io.open("log.txt", io.Append)?
defer file.close()
file.write("entry\n")?

line := io.stdin.readLine()?

json — JSON (Implemented)

Pure Aria JSON library (558 lines). Implemented in lib/json.aria:

// Parse JSON string to value
val := json_parse(jsonString)

// Emit value back to JSON string
output := json_emit(val)

// Access fields
name := json_get_str(val, "name")
count := json_get_int(val, "count")

// Set fields
json_set_field(val, "updated", true_val)

http — HTTP Server (Implemented)

Pure Aria HTTP 1.0 server (227 lines). Implemented in lib/http.aria:

// Start an HTTP server
http_serve("0.0.0.0", 8080)

// Define a handler
fn http_handler(req: HttpRequest) -> str {
    http_response_json(200, "{\"status\": \"ok\"}")
}

// Parse raw request
req := http_parse_request(raw)

// Build responses
resp := http_response(200, "Hello, World!")
resp := http_response_json(200, jsonData)
http_add_header(resp, "X-Custom", "value")

postgres — PostgreSQL Client (Implemented)

PostgreSQL client wrapping libpq (123 lines). Implemented in lib/postgres.aria. Optional — requires ARIA_HAS_LIBPQ at compile time:

// Connect
conn := pg_connect("host=localhost dbname=mydb")

// Query
result := pg_query(conn, "SELECT * FROM users WHERE active = $1", "true")

// Close
pg_close(conn)

net — TCP Networking (Runtime)

TCP primitives in the runtime, cross-platform (POSIX sockets on Unix, winsock2 on Windows):

// TCP server
sock := _aria_socket(2, 1)  // AF_INET, SOCK_STREAM
_aria_bind(sock, "0.0.0.0", 8080)
_aria_listen(sock, 128)
client := _aria_accept(sock)

// Read/write
data := _aria_recv(client, 4096)
_aria_send(client, response)

Planned Modules

The following modules are specified but not yet implemented:

  • time — time, duration, formatting
  • crypto — hashing, password hashing
  • log — structured logging
  • math — math functions

Serialization with Derives

derives generates actual method bodies. Eq generates field-by-field comparison, Clone generates field copying, Debug generates formatted string output:

struct User {
    id: i64
    name: str
    email: str
} derives [Eq, Clone, Debug]

u1 := User{id: 1, name: "Alice", email: "a@b.com"}
u2 := u1.clone()
assert u1 == u2
println(u1.debug())  // User{id: 1, name: Alice, ...}

Next Steps