Data Types
DOCUMENTATION
XCX 4.4.1 Data Types
Simple Types
| Symbol | Type | Default | Example |
|---|---|---|---|
i / int | Integer | 0 | 42, -7, 0 |
f / float | Float | 0.0 | 3.14, -0.5, 2.0 |
s / str | String | "" | "hello", "" |
b / bool | Boolean | false | true, false |
date | Date | 1970-01-01 | date("2024-12-25") |
json | JSON Object | null | <<< {"key": "value"} >>> |
Complex Types
| Symbol | Type | Declaration Example |
|---|---|---|
array:i | Array of integers | array:i: nums {1, 2, 3} |
array:f | Array of floats | array:f: vals {1.0, 2.5} |
array:s | Array of strings | array:s: words {"a", "b"} |
array:b | Array of booleans | array:b: flags {true, false} |
array:json | Array of JSON objects | array:json: items |
set:N | Set of Natural numbers | set:N: s {1,,10} |
set:Z | Set of Integers | set:Z: s {-2, 0, 2} |
set:Q | Set of Rational (float) | set:Q: s {0.5, 1.0, 1.5} |
set:S | Set of Strings | set:S: s {"a", "b"} |
set:B | Set of Booleans | set:B: s {true, false} |
set:C | Set of Characters | set:C: s {"A",,"Z"} |
map | Key-Value Map | map: m { schema = [s <-> i] data = [...] } |
table | Relational Table | table: t { columns = [...] rows = [...] } |
database: | Database Connection | database: db { engine = "sqlite", path = "app.db" } |
fiber:T | Typed Fiber | fiber:b: f = my_fiber(arg) |
fiber: | Void Fiber | fiber: 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.