Built-ins¶
Use these helpers for console input and output, basic calculations, time, and information about the running program. Console and system helpers need import system;; Math and primitive methods are available automatically.
Import: import system; for console, env, and process helpers. Math, Array, and primitive methods need no import.
Console¶
| Call | What it does |
|---|---|
System.print(x) |
write without a newline |
System.println(x) |
write, then newline |
System.set_foreground / set_background / reset_color() |
color until reset |
System.clear() |
clear the terminal |
System.read_line() |
one line of input; parse it with int.parse(line), double.parse(line), or bool.parse(line) |
System.read_key() |
one character |
System.exit(code) |
stop the process |
System.panic(message) |
print and halt — see Panics |
System.stdin / stdout / stderr |
byte streams implementing Reader / Writer (import system.io) |
Platform and env¶
| Call | What it does |
|---|---|
System.platform / System.os_family |
which host you are on; compare System.platform == Platform.Browser to detect a page |
System.args |
command-line arguments |
System.exe_path |
path of this executable, if any |
System.env(name) / env_keys |
environment variables; env returns Option<string>, so use unwrap_or(fallback) for a default and is_some() to test presence |
System.set_env(name, value) / unset_env(name) |
set or clear an env var |
System.cwd / set_cwd(path) |
working directory |
System.temp_dir / home_dir |
temp and home paths |
System.cpu_time_nanos |
process user+system CPU time since start |
System.memory_bytes |
OS resident memory (RSS / working set); 0 if unknown |
Math (no import)¶
Example: Math.sqrt(9.0) → 3.0. A negative input is NaN.
Math.floor, ceil, round, sqrt, pow, sin / cos / tan, asin / acos / atan / atan2, log / log10 / exp / hypot, and Math.PI / Math.E. Angles are radians. round sends halfway cases away from zero (Math.round(-2.5) is -3.0). Every function gives the same result on native and WebAssembly targets.
Absolute value, minimum, maximum, and clamping are methods on the number itself: x.abs(), x.min(y), x.max(y), and x.clamp(low, high).
Timing¶
Time.delay(ms).await / Time.sleep(ms).await need an async function. Time.nano_time() is a monotonic clock. Stopwatch times a span — also on DateTime.
Other¶
.lengthon strings, arrays, and collections.Array.alloc<T>(n)— a zeroed fixed array. Prefer List when the size grows.- Override
public override fun to_string()soprintand+show your type. See object.
Waiting for cancellation¶
Cancellation tokens can suspend until cancellation, or wait for another future while
observing cancellation. Waits use scheduler notifications rather than periodic checks.
wait returns Err(CancelledError) and cancels the supplied future when cancellation
wins; completed side effects remain observable. A wait detaches its subscription on completion or when its cancelled future is
released. Tokens retain their existing cross-worker sharing behavior.
Use wait_void for a Future<void>; it returns Ok(Unit()) when the operation completes.