Standard Library
Quartz comes with a comprehensive standard library organized into system modules. All modules are implemented as native C++ extensions and are loaded automatically at runtime.
Import Syntax
import system.MODULE as ALIAS;
Always use an alias when importing modules. Some module names (like string) are keywords and require aliasing.
Available Modules
📥 system.io
Input/output operations for console communication.
- println
- readln
🔢 system.math
Mathematical operations and trigonometric functions.
- abs
- sqrt
- pow
- sin
- cos
- floor
- ceil
📝 system.string
String manipulation and analysis functions.
- length
- uppercase
- lowercase
- trim
- contains
- replace
🔄 system.convert
Type conversion between primitive types.
- toInt
- toDouble
- toString
- toBool
📚 system.collection
Array and collection manipulation functions.
- map
- filter
- reduce
- length
- push
- pop
⏰ system.time
Date and time functions.
- now
- sleep
- timestamp
system.io - Input/Output
The I/O module provides console input and output operations.
import system.io as io;
// Output
io.out.println("Hello, World!");
io.out.println("Multiple", "arguments", "work");
io.out.print("No newline");
// Input
let name = io.stdin.readln();
Functions
| Function | Description |
|---|---|
| `io.out.println(...)` | Print arguments with newline |
| `io.out.print(...)` | Print arguments without newline |
| `io.stdin.readln()` | Read a line from stdin |
system.math - Mathematics
Mathematical functions for numeric operations.
import system.math as math;
let x = math.sqrt(16); // 4.0
let y = math.pow(2, 8); // 256.0
let z = math.abs(-42); // 42
let angle = math.sin(3.14); // ~0
Functions
| Function | Description |
|---|---|
| `math.abs(x)` | Absolute value |
| `math.sqrt(x)` | Square root |
| `math.pow(base, exp)` | Power function |
| `math.floor(x)` | Round down |
| `math.ceil(x)` | Round up |
| `math.round(x)` | Round to nearest |
| `math.min(a, b)` | Minimum of two values |
| `math.max(a, b)` | Maximum of two values |
| `math.sin(x)` | Sine (radians) |
| `math.cos(x)` | Cosine (radians) |
system.string - String Manipulation
Functions for working with strings.
import system.string as str;
let text = " Hello World ";
let len = str.length(text); // 15
let upper = str.uppercase(text); // " HELLO WORLD "
let trimmed = str.trim(text); // "Hello World"
let found = str.contains(text, "World"); // true
Functions
| Function | Description |
|---|---|
| `str.length(s)` | String length |
| `str.uppercase(s)` | Convert to uppercase |
| `str.lowercase(s)` | Convert to lowercase |
| `str.trim(s)` | Remove whitespace |
| `str.contains(s, sub)` | Check if contains substring |
| `str.startsWith(s, prefix)` | Check prefix |
| `str.endsWith(s, suffix)` | Check suffix |
| `str.substring(s, start, end)` | Extract substring |
| `str.replace(s, find, replace)` | Replace occurrences |
system.convert - Type Conversion
Convert between types safely.
import system.convert as conv;
let i = conv.toInt("42"); // 42
let d = conv.toDouble("3.14"); // 3.14
let s = conv.toString(100); // "100"
let b = conv.toBool("true"); // true
Conversion Rules
- String to Int: Parses integer, returns 0 on failure
- String to Double: Parses float, returns 0.0 on failure
- String to Bool: "true", "1", "yes" → true; others → false
- Number to Bool: 0 → false; non-zero → true
system.collection - Collections
Higher-order functions for working with arrays.
import system.collection as c;
let nums = [1, 2, 3, 4, 5];
// Map - transform each element
let doubled = c.map(nums, (x) => x * 2);
// [2, 4, 6, 8, 10]
// Filter - keep elements matching predicate
let evens = c.filter(nums, (x) => x % 2 == 0);
// [2, 4]
// Reduce - accumulate to single value
let sum = c.reduce(nums, 0, (acc, x) => acc + x);
// 15
Extension Architecture
All standard library modules are implemented as native C++ extensions:
- Location:
extensions/system_*/ - Auto-loaded: Yes, at runtime startup
- Thread-safe: Yes, functions use proper synchronization
You can create your own extensions using the same architecture. See the Extensions Guide for details.