A scalar type represents a single value. Ox has three primitive scalar types:
- Boolean,
- Floating-point, and
- Integer.
The Boolean
data type represents the two truth values (true
and false
) of Boolean algebra.
BOOLEAN LITERAL = “true” | “false”;
Size | Signedness | |
---|---|---|
16-bit Floating-point |
16-bit |
signed |
32-bit Floating-point |
32-bit |
signed |
64-bit Floating-point |
64-bit |
signed |
FLOATING POINT LITERAL = ...;
Size | Signedness | |
---|---|---|
unsigned 8-bit Integer |
8-bit |
unsigned |
8-bit Integer |
8-bit |
signed |
unsigned 16-bit Integer |
16-bit |
unsigned |
16-bit Integer |
16-bit |
signed |
unsigned 32-bit Integer |
32-bit |
unsigned |
32-bit Integer |
32-bit |
signed |
unsigned 64-bit Integer |
64-bit |
unsigned |
64-bit Integer |
64-bit |
signed |
unsigned 128-bit Integer |
128-bit |
unsigned |
128-bit Integer |
128-bit |
signed |
unsigned Integer |
Arbitrary-precision |
unsigned |
Integer |
Arbitrary-precision |
signed |
INTEGER LITERAL = ...;
A compound data type groups multiple values into one type.
An array is a homogenous sequence:
a: [4 × unsigned 8-bit Integer] ← [0, 0, 0, 0];
a: [(2 × 4) × Integer] ← [[0, 0, 0, 0], [0, 0, 0, 0]];
a: [4 × unsigned 8-bit Integer] ← [1, 2, 3, 4];
a[0]; # 1
a[1]; # 2
b: [(2 × 4) × Integer] ← [[1, 2, 3, 4], [1, 2, 3, 4]];
b[0, 0] # 1
b[0, 1] # 2
b[:, 0] # [1, 1]
b[0, :] # [1, 2, 3, 4]
ARRAY-TYPE = “[” SHAPE “×” TYPE “]”;
A tuple is a heterogeneous sequence:
example: (unsigned 8-bit Integer, Boolean, Boolean) ← (0, true, true);
ANONYMOUS-FUNCTION = “λ” PARAMETERS "{" EXPRESSION "}";
subroutine example {a: Integer} → Integer {
return λ {b} {
a + b;
}
}
x: Integer ← example(1)(1); # 2
UNARY-OPERATION = "{" PARAMETER "}" “→” TYPE “{“ EXPRESSION “}”;
BINARY-OPERATION = "{" PARAMETER "," PARAMETER "}" “→” TYPE “{“ EXPRESSION “}”;
“infix” “operator” OPERATOR BINARY-OPERATION;
infix operator + {a: Integer, b: Integer} → Integer {
…
}
x: Integer ← 1 + 1;
“prefix” “operator” OPERATOR UNARY-OPERATION;
prefix operator ¬ {a: Boolean} → Boolean {
…
}
x: Boolean ← ¬true;
“postfix” “operator” OPERATOR UNARY-OPERATION;
postfix operator ! {a: Integer} → Integer {
…
}
x: Integer ← 5!