YaoXiang Reference Documentation
This documentation is under construction...
YaoXiang is currently in the experimental verification phase, and the standard library and API are being gradually improved.
Language Specification
- Language Specification Overview
- Syntax Specification - Lexical structure, syntax rules, operator precedence
- Type System - Basic types, composite types, generics, trait
- Module System - Module definition, import/export, scope
- Concurrency Model - Async programming, concurrency primitives, memory model
- Standard Library - Core library, IO library, math library
Current Status
| Module | Status | Description |
|---|---|---|
std.io | 🔨 In progress | Input/Output |
std.string | 🔨 In progress | String operations |
std.list | 🔨 In progress | List operations |
std.dict | 📋 Planned | Dictionary operations |
std.math | 🔨 In progress | Math functions |
std.net | 📋 Planned | Network operations |
std.concurrent | 📋 Planned | Concurrency primitives |
Built-in Types
Primitive Types
| Type | Description | Example |
|---|---|---|
Void | Void/null return | () |
Bool | Boolean value | true, false |
Int | Integer | 42, -10 |
Float | Floating-point number | 3.14, -0.5 |
Char | Character | 'a', '中' |
String | String | "hello" |
Composite Types
| Type | Description | Example |
|---|---|---|
List(T) | List of same-type elements | [1, 2, 3] |
Tuple(T1, T2, ...) | Tuple of different elements | (1, "hello") |
Dict(K, V) | Key-value map | {"a": 1} |
(Args) -> Ret | Function type | (Int) -> Int |
User-Defined Types
yaoxiang
// 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
yaoxiang
print(value) // Print without newline
println(value) // Print with newlineConversion
yaoxiang
to_string(value) // Convert to string
to_int(value) // Convert to integer
to_float(value) // Convert to floating-pointType Checking
yaoxiang
typeof(value) // Return type name
is_type(value, type) // Check typeKeywords
| Keyword | Description |
|---|---|
Type | Meta type |
spawn | Mark spawn function |
spawn for | Parallel loop |
spawn {} | Spawn block |
if / else if / else | Conditional branch |
match | Pattern matching |
while / for | Loop |
return | Return value |
ref | Create reference |
mut | Mutable marker |
Syntax Quick Reference
Variable Declaration
yaoxiang
// Immutable variable (default)
x: Int = 42
y = 42 // Type inference
// Mutable variable
mut count: Int = 0
count = count + 1Function Definition
yaoxiang
// Regular function
add: (a: Int, b: Int) -> Int = a + b
// Spawn function (automatic concurrency)
fetch: (url: String) -> JSON spawn = HTTP.get(url).json()
// Generic function
identity: [T](x: T) -> T = xControl Flow
yaoxiang
// Conditional
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
yaoxiang
// ? operator propagates error
data = fetch_file(path)?Operator Precedence
| Precedence | Operator |
|---|---|
| Highest | ( ) Function call |
. Field access | |
[ ] Index | |
unary - Unary minus | |
* / % Mul/Div/Mod | |
+ - Add/Subtract | |
== != < > <= >= Comparison | |
and or Logical ops | |
| Lowest | = Assignment |
Standard Library Usage Examples
yaoxiang
// Import 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}
// Usage
println("Hello, YaoXiang!")
result = sqrt(16.0) // 4.0Command Line Tools
bash
# Run script
yaoxiang run hello.yx
# Build bytecode
yaoxiang build hello.yx -o hello.42
# Interpret and execute
yaoxiang eval 'println("Hello")'
# View help
yaoxiang --helpComplete Example
yaoxiang
// Calculate Fibonacci sequence
fib: (n: Int) -> Int = if n <= 1 {
n
} else {
fib(n - 1) + fib(n - 2)
}
// Main function
main: () -> Void = {
print("Fibonacci(10) = " + fib(10).to_string())
}Related Resources
- Tutorial - Learn YaoXiang
- Design Documents - Language design decisions
- GitHub
Contribution Guide
The standard library is under construction, contributions are welcome!
- Choose a module (e.g.,
std.io,std.net) - Implement functions in
src/std/ - Add documentation comments
- Submit PR
