DOCUMENTATION

Data Types

DOCUMENTATION

XCX 4.4.1 Data Types

Simple Types

SymbolTypeDefaultExample
i / intInteger042, -7, 0
f / floatFloat0.03.14, -0.5, 2.0
s / strString"""hello", ""
b / boolBooleanfalsetrue, false
dateDate1970-01-01date("2024-12-25")
jsonJSON Objectnull<<< {"key": "value"} >>>

Complex Types

SymbolTypeDeclaration Example
array:iArray of integersarray:i: nums {1, 2, 3}
array:fArray of floatsarray:f: vals {1.0, 2.5}
array:sArray of stringsarray:s: words {"a", "b"}
array:bArray of booleansarray:b: flags {true, false}
array:jsonArray of JSON objectsarray:json: items
set:NSet of Natural numbersset:N: s {1,,10}
set:ZSet of Integersset:Z: s {-2, 0, 2}
set:QSet of Rational (float)set:Q: s {0.5, 1.0, 1.5}
set:SSet of Stringsset:S: s {"a", "b"}
set:BSet of Booleansset:B: s {true, false}
set:CSet of Charactersset:C: s {"A",,"Z"}
mapKey-Value Mapmap: m { schema = [s <-> i] data = [...] }
tableRelational Tabletable: t { columns = [...] rows = [...] }
database:Database Connectiondatabase: db { engine = "sqlite", path = "app.db" }
fiber:TTyped Fiberfiber:b: f = my_fiber(arg)
fiber:Void Fiberfiber: f = my_void_fiber(arg)

array:json

array:json is an array storing elements of type json. Used primarily when working with HTTP responses that return arrays of JSON objects.

$ xcx
_ ⛶ ×
1--- Declare an empty JSON array
2array:json: items;
3
4--- Iterate over a JSON array (e.g. from a network response)
5i: size = resp.body.size();
6i: idx = 0;
7while (idx < size) do;
8 json: item = resp.body.get(idx);
9 s: name; item.bind("name", name);
10 >! name;
11 idx = idx + 1;
12end;
13
14--- Add an element
15json: obj <<< {"key": "value"} >>>;
16items.push(obj);

Methods on array:json are identical to other array types (.push(), .pop(), .get(i), .size(), etc.).

database:

database: represents a connection to a relational database. Declared with a configuration block and used through its built-in methods. See Database Documentation for the full API.

$ xcx
_ ⛶ ×
1database: app {
2 engine = "sqlite",
3 path = "app.db"
4};
5
6yield app.sync(users);
7table: all = yield app.fetch(users);

Default Values

$ xcx
_ ⛶ ×
1int: def_int; --- 0 (alias for i)
2float: def_float; --- 0.0 (alias for f)
3str: def_str; --- "" (alias for s)
4bool: def_bool; --- false (alias for b)

Type Casting

$ xcx
_ ⛶ ×
1f: x = 3.7;
2i: n = i(x); --- 3 (truncate toward zero)
3
4i: m = 42;
5f: y = f(m); --- 42.0
6
7i: num = 99;
8s: str = s(num); --- "99"

NOTE:

b → i conversion is intentionally blocked. true + 1 is a type error to prevent logical bugs common in C-family languages.