Documentation
Built-in Types
Built-in Types
Choose explicit scalar types for arithmetic and annotated collection types for
stored data. Accepted type spellings live in
packages/arx/src/arx/lexer/syntax.json; a lexical name alone does not
establish executable support. See the capability matrix
for that boundary and type annotations for placement.
Scalars and conversions
Use fixed-width integers or floats when width matters, bool for conditions,
and str for UTF-8 text. char is a low-level i8 representation, not a
Unicode grapheme. none is both the unit type and its sole value; a -> none
function may use bare return, return none, or fall through.
cast(value, Type) requests a supported conversion. isinstance(value, Type)
checks the semantic type, including finite union aliases; type(value) returns
its name. These do not introduce dynamic Python objects or runtime tagged
unions. See the executable
datatype tests
and
preview arithmetic contract.
Strings have distinct static, borrowed, and owned lifetimes; consult the string ownership contract before returning or storing borrowed text. Native strings cannot represent embedded NUL safely.
Parsing text
fn distance(record: str) -> i64:
clean: str = record.strip()
return int(clean[1:])
For whitespace-delimited input, iterate over text.split(). The returned
strings and list own their storage, including after the source file is closed or
its text replaced. Advanced splitting can preserve empty fields with
text.split(sep=",", maxsplit=2); strip(chars="xy") removes a set of code
points, not the substring "xy". Explicit empty separators fail.
len(text) and indexing count Unicode code points, not bytes or grapheme
clusters; no normalization occurs. Slices clip nonnegative bounds, but negative
indices/bounds and non-unit steps are unsupported. ord(text) requires exactly
one code point. int(text, base=10) returns checked i64, with bases 2–36;
unlike Python it does not recognize base prefixes or digit separators, and
digits are ASCII only. Numeric casts still use cast, not int. Whitespace is
locale-independent and shared by splitting, stripping and integer parsing; its
exact set is specified in the native text source contract. Invalid text/options
and overflow raise recoverable errors rather than returning partial data. Text
literals and text-file reads reject embedded NUL; arbitrary octets use bytes
and binary File methods instead.
chr(codepoint) encodes one nonzero Unicode scalar as str, and rejects
surrogates and out-of-range values. text.codepoints() returns the scalar
values as an owned list[i64]. float(text) parses decimal text as f64 using
locale-independent native rounding. It accepts a sign, decimal point, exponent,
and surrounding whitespace. Malformed numbers raise ValueError, and
conversions to infinity raise OverflowError.
Byte values
bytes([0, 255, 13, 10]) creates an immutable, length-aware octet buffer.
bytes() is empty; bytes(existing) makes an independent copy. len(data)
counts bytes and nonnegative indexing returns u8; indexing outside the buffer
raises IndexError. NUL and invalid UTF-8 are ordinary bytes. This is not an
Arrow binary column and does not require Arrow.
Construction checks every integer in 0–255 without wrapping; Boolean, float,
nullable, and text inputs are rejected. Sized integer sequences are accepted;
single-pass iterators require an explicit max_items bound. An invalid value or
exceeded bound publishes no partial buffer, but consumed input is not rewound.
Unlike Python, scalar zero-fill construction, text encoding, and byte slices are
not implemented.
Content is immutable, but a local binding can be replaced. Buffers use the owned
list lifecycle: parameters borrow; fresh results and returned local owners
transfer ownership. Implicit local aliases are rejected: use bytes(existing)
for a copy. Byte buffers in class/struct fields, nested containers, globals,
extern signatures, and generator-owned storage are not supported. Independent
binary reads can outlive their File.
Temporal scalars
date, time, datetime, and timestamp are distinct scalar types. Values
can be passed to functions, returned, stored in locals, and compared with values
of the same type. date represents a Gregorian calendar day, time represents
a time of day, and datetime represents calendar fields without a timezone.
timestamp represents a UTC instant to microsecond precision. A timezone-free
timestamp(...) literal denotes UTC.
The literal constructors accept string literals. Use stdlib.temporal to parse
strings at runtime and format values back to ISO text. Timestamp text passed to
temporal.parse_timestamp requires Z or a numeric UTC offset. The
corresponding formatter emits UTC with Z. Use from_unix_us and to_unix_us
for signed Unix microseconds. Dates and timestamps support years 0001
through 9999. Invalid input text raises ValueError, and an instant outside
that calendar range raises OverflowError.
import temporal from stdlib
fn normalize_event_time(text: str) -> str:
return temporal.format_timestamp(temporal.parse_timestamp(text))
Use temporal.now() to record a UTC timestamp and temporal.today_utc() to get
the current UTC date. For elapsed time, subtract two readings from
temporal.monotonic_ns(). Use temporal.sleep(seconds) to block the calling
thread for a finite nonnegative duration.
Collections and nullable values
Collections and Apache Arrow owns the list, tensor, DataFrame, and Series storage rules. In particular, runtime-schema DataFrames support locals and returns, while runtime-shaped tensors remain parameter-only. Arrow schema types and temporal scalar types have different conversion rules.
Nullable expressions carry explicit validity, propagate nulls, and use checked arithmetic. They are not interchangeable with non-nullable scalar arithmetic or Boolean conditions.
File references
File and open create shared class references to one text or
binary stream; lowercase file denotes the same type. References can be
aliased, passed, returned, and stored in supported class fields. Closing through
any alias closes the shared stream. Only the hidden native handle is uniquely
owned.