Runtime
Panics
A panic is a hard, unrecoverable runtime error. It prints a message and exits the process with a non-zero status. Panics cannot be caught.
Panics are triggered by:
.yolo()onNoneor aResult::Err- Out-of-bounds array access
- Integer division by zero
assert(false)orassert_msg(false, msg)
Built-in Functions
These are available in every module without any import declaration (provided by std::core auto-import):
| Name | Signature | Description |
|---|---|---|
print | <T>(v: T) | Print to stdout, no newline |
println | <T>(v: T) | Print to stdout with newline |
string_len | (s: String) -> Int | Number of characters in a string |
string_concat | (a: String, b: String) -> String | Concatenate two strings |
array_push | (arr: T[], value: T) | Append a value (mutates the array) |
array_len | (arr: T[]) -> Int | Number of elements in an array |
clock | () -> Int | Unix timestamp in milliseconds |
assert | (cond: Bool) | Panic with "assertion failed" if cond is false |
assert_msg | (cond: Bool, msg: String) | Panic with msg if cond is false |
dbg | <T>(v: T) -> T | Print [dbg] <value> to stderr and return the value unchanged |
Built-in Aspects
The following aspects are pre-implemented for built-in types:
Display
aspect Display {
fun to_string(self) -> String;
}
Int, Float, Bool, and String implement Display. .to_string() returns the canonical string representation. print and println accept any Display type.
Iterable<T>
aspect Iterable<T> {
fun next(mut self) -> Perhaps<T>;
}
T[] (array) and Range (from .. / ..=) implement Iterable<T>. User-defined types may implement it to be usable in for-in.
From<S>
aspect From<S> {
fun from(value: S) -> Self;
}
Int implements From<Float> (truncating cast) and Float implements From<Int>. The as operator desugars to T::from(value). User-defined types may implement From<S> to enable as casts and ? error coercion.
String Methods
| Method | Signature | Description |
|---|---|---|
.len() | () -> Int | Number of characters in the string |
.to_string() | () -> String | Returns the string itself |