Gradual Type System, struct, enum, match & Closures
RaggieScript v1.0 features a gradual, type-inferred static type checker (BindAndVerifyProgram). Simple setup scripts can omit type annotations entirely and rely on local type inference, while larger engineering suites can annotate struct schemas, enum variants, and fn return contracts checked at compile time (RSW710–RSW715).
Built-In Primitive & Composite Types
| Type Annotation | Runtime Representation | Assignability & Widening Notes |
|---|---|---|
int | 64-bit signed integer (int64_t) | Widens automatically to float. |
float | 64-bit IEEE double (double) | Accepts both float and int. |
bool | Boolean (true / false) | Strict in relational comparisons (RSW711 blocks < on bool). |
string | UTF-8 string | Interoperates cleanly with path and string-backed enum variants. |
path | Normalized filesystem path | Supports / path-join operator (sys.programFiles / "RaggieSoft" -> path). |
version | 4-part SemVer (Major.Minor.Build.Rev) | Compared component-wise (v"10.0.22631" > v"10.0.22000"). |
array | Ordered list (T[] shorthand accepted) | Indexed via arr[i]; supports len(arr), array.map, array.filter. |
map | Key-value dictionary | Supports dot-property m.key and bracket m["key"] access. |
ref T | Mutable variable reference | Required by two-way Wizard UI bind: ref myParam slots (const blocked by RSW713). |
any | Gradual dynamic escape hatch | Compatible with any target or source type. |
User-Defined Records (struct)
struct declarations define strongly checked record types with optional default field values. Passing an unknown field name or wrong field type in a struct literal raises RSW714 or RSW711 at compile time (with a fuzzy "Did you mean ...?" suggestion!):
struct EndpointConfig {
host: string = "https://raggiesoftstudio.com";
port: int = 443;
tlsVerify: bool = true;
}
const prod = EndpointConfig {
port: 8443 // 'host' and 'tlsVerify' inherit their declared defaults!
};
Strongly-Typed Enumerations (enum)
enum declarations group named string or integer constants. Referencing a misspelled variant (ReleaseRing.Stabel) fails immediately at compile time with RSW714:
enum ReleaseRing {
Stable = "stable",
Preview = "preview",
Lts = "lts"
}
param ring: ReleaseRing = ReleaseRing.Stable;
Pattern Matching (match)
match can be used as an expression (returning a value) or as a statement, with _ (or default) serving as the wildcard catch-all arm:
fn siliconBanner(arch: string) : string {
return match (arch) {
"arm64" => "Native Windows 11 ARM64 Build",
"x64" => "Native Windows 11 x64 Build",
_ => "64-Bit Windows Build"
};
}
Functions (fn) & First-Class Arrow Closures (=>)
User functions support typed parameters, default parameter expressions, return type annotations (verified on all control paths via RSW715), and mutual recursion.
First-class arrow closures (x => expr, (a: int, b: int) => expr, or () => { ... }) capture lexical variables from outer scopes and compile to MAKE_CLOSURE opcodes in the RSWBC2 stack VM:
// 1. Named typed function with default argument
fn formatPortEndpoint(host: string, port: int = 443) : string {
return "${host}:${port}";
}
// 2. First-class closure passed to ui.textBox(validate: ...) or array.filter(...)
const minPort = 1024;
const isValidServicePort = (raw: string) => {
const p = int(str.trim(raw));
return (p >= minPort && p <= 65535)
? Validation.ok()
: Validation.error("Enter a TCP port between ${minPort} and 65535.");
};
const ports = [80, 443, 8080, 9443];
const unprivileged = array.filter(ports, p => p >= minPort); // -> [8080, 9443]