YaoXiang Reference Documentation
YaoXiang is currently in the experimental validation stage (for the current version, see Language Specification Overview). The standard library and APIs are being gradually refined.
The authoritative module-by-module reference for the standard library is available in the Standard Library Reference. This page serves only as an entry-point index.
Reference Entry Points
- Error Code Reference - Overview of diagnostic codes and category-based lookup
- Warning Codes
- Package Management - Manifests, lockfiles, and commands
- Tool Commands / format / test
Language Specification
- Language Specification Overview
- Syntax Specification - Lexical structure, syntax rules, and operator precedence
- Type System - Primitive types, composite types, generics, and traits
- Module System - Module definitions, imports and exports, and scopes
- Concurrency Model - Asynchronous programming, concurrency primitives, and the memory model
- FFI - Foreign function interface
- Standard Library - Overview of the standard library
Current Status
| Module | Status | Description | Reference |
|---|---|---|---|
std.io | ✅ Implemented | Input and output | io |
std.string | ✅ Implemented | String operations | string |
std.list | ✅ Implemented | List operations | list |
std.dict | ✅ Implemented | Dictionary operations | dict |
std.range | ✅ Implemented | Ranges and iterators (#302) | range |
std.math | ✅ Implemented | Mathematical functions | math |
std.net | ✅ Implemented | Network operations (ureq + rustls) | net |
std.concurrent | ✅ Implemented | Concurrency primitives | concurrent |
std.os | ✅ Implemented | Operating system interfaces | os |
std.fs | ✅ Implemented | File system | fs |
std.time | ✅ Implemented | Time and date | time |
std.convert | ✅ Implemented | Type conversion | convert |
std.result | ✅ Implemented | Result type | result |
std.assert | ✅ Implemented | Assertions | assert |
std.weak | ✅ Implemented | Weak references | weak |
In its early stages,
std.netwas a “placeholder implementation that did not send requests.” It has now been changed to a real implementation (#56).
Built-in Types
Primitive Types
| Type | Description | Examples |
|---|---|---|
Never | Zero constructor (divergence) | — |
Void | No value / no return value | () |
Bool | Boolean value | true, false |
Int | Integer (= Int64) | 42, -10 |
Int8 | 8-bit integer | 1 |
Int16 | 16-bit integer | 1 |
Int32 | 32-bit integer | 1 |
Int64 | 64-bit integer | 1 |
Float | Floating-point number (= Float64) | 3.14, -0.5 |
Float32 | 32-bit floating-point number | 3.14 |
Float64 | 64-bit floating-point number | 3.14 |
Char | Character | 'a', '中' |
String | String | "hello" |
Bytes | Raw bytes | — |
These are all 15 built-in type names (
()is how theVoidtype is written). See the authoritative table and spelling rules in Language Specification §2.1: only the capitalized spelling is valid. Names such asint/i64/str/boolare not type names.DateTimeis not a built-in name—now/parse_timeinstd.timereturn anInttimestamp (writing a bareDateTimeannotation produces an unknown-type error).
Composite Types
| Type | Description | Examples |
|---|---|---|
Tuple(T1, T2, ...) | Tuple of heterogeneous elements | (1, "hello") |
(Args) -> Ret | Function type | (Int) -> Int |
#299: Container types (
List(T)/Vec(T)/Array(T, N)/Dict(K, V)) are not built-in primitives—they are generic type constructors, treated the same as user-defined generics and processed through a unified generic instantiation path. Literal syntax ([...]/{...}) remains in the core, with its destination determined by contextual inference. Set has been removed (#300); see the Language Specification.The three container concepts are distinguished by where their length information resides:
Array(T, N)stores its length in the type (fixed-length),Vec(T)stores its length as a runtime value (raw-buffer primitive), andList(T)is a standard library type ({ data: Vec(T), length: Int }, with all policies implemented in the library).
User-defined Types
// Record type (struct)
Point: Type = { x: Float, y: Float }
// Enum type
Result: (T: Type, E: Type) -> Type = { ok: (T) -> Result(T, E), err: (E) -> Result(T, E) }
// Interface type (all fields are functions)
Callable: Type = { call: (String) -> Void }Built-in Functions
Output
print(value) // Print without a newline
println(value) // Print with a newlineConversion
to_string(value) // Convert to a string
to_int(value) // Convert to an integer
to_float(value) // Convert to a floating-point numberType Checking
typeof(value) // Return the type name
is_type(value, type) // Check the typeKeywords
| Keyword | Description |
|---|---|
Type | Meta-type |
spawn | Marks a spawn function |
spawn for | Parallel loop |
spawn {} | Spawn block |
if / else if / else | Conditional branches |
match | Pattern matching |
while / for | Loops |
return | Return value |
ref | Create a reference |
mut | Mutable marker |
Syntax Quick Reference
Variable Declaration
// Immutable variable (default)
x: Int = 42
y = 42 // Type inference
// Mutable variable
mut count: Int = 0
count = count + 1Function Definition
// Regular function
add: (a: Int, b: Int) -> Int = a + b
// Spawn function (automatically concurrent)
fetch: (url: String) -> JSON spawn = HTTP.get(url).json()
// Generic function
identity: [T](x: T) -> T = xControl Flow
// Condition
if x > 0 {
print("positive")
} else if x < 0 {
print("negative")
} else {
print("zero")
}
// Pattern matching
match result {
ok(value) -> print("success: " + value),
err(error) -> print("error: " + error),
}
// Loop
for i in 0..10 {
print(i)
}Error Handling
// The ? operator propagates errors
data = fetch_file(path)?Operator Precedence
| Precedence | Operator |
|---|---|
| Highest | ( ) function call |
. field access | |
[ ] indexing | |
unary - unary minus | |
* / % multiplication, division, modulo | |
(Operator precedence and associativity are fixed by the language; the semantics of + - * / %, == !=, and [] can be type-overloaded by the corresponding implementation interfaces (RFC-011b)) | |
+ - addition and subtraction | |
== != < > <= >= comparison | |
and or logical operations | |
| Lowest | = assignment |
Standard Library Usage Examples
// Import the standard library
use std.io.{print, println}
// List operations
use std.list.{list_push, list_pop, list_len}
// Math functions
use std.math.{sqrt, sin, cos, PI}
// Use
println("Hello, YaoXiang!")
result = sqrt(16.0) // 4.0Command-Line Tools
# Run the script
yx run hello.yx
# Build bytecode
yx build hello.yx -o hello.42
# Interpret and execute
yx eval 'println("Hello")'
# View help
yaoxiang --helpComplete Example
use std.convert
use std.io
// Calculate the Fibonacci sequence
fib: (n: Int) -> Int = if n <= 1 {
n
} else {
fib(n - 1) + fib(n - 2)
}
// Main function
main: () -> Void = {
io.println("Fibonacci(10) = " + convert.to_string(fib(10)))
}Related Resources
- Tutorial - Learn YaoXiang
- Design Documentation - Language design decisions
- GitHub
Contributing Guidelines
The standard library is under construction, and contributions are welcome!
- Choose a module (such as
std.ioorstd.net) - Implement functions in
src/std/ - Add documentation comments
- Submit a PR
