Skip to content

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 ​

Language Specification ​

Current Status ​

ModuleStatusDescriptionReference
std.io✅ ImplementedInput and outputio
std.string✅ ImplementedString operationsstring
std.list✅ ImplementedList operationslist
std.dict✅ ImplementedDictionary operationsdict
std.range✅ ImplementedRanges and iterators (#302)range
std.math✅ ImplementedMathematical functionsmath
std.net✅ ImplementedNetwork operations (ureq + rustls)net
std.concurrent✅ ImplementedConcurrency primitivesconcurrent
std.os✅ ImplementedOperating system interfacesos
std.fs✅ ImplementedFile systemfs
std.time✅ ImplementedTime and datetime
std.convert✅ ImplementedType conversionconvert
std.result✅ ImplementedResult typeresult
std.assert✅ ImplementedAssertionsassert
std.weak✅ ImplementedWeak referencesweak

In its early stages, std.net was a “placeholder implementation that did not send requests.” It has now been changed to a real implementation (#56).

Built-in Types ​

Primitive Types ​

TypeDescriptionExamples
NeverZero constructor (divergence)—
VoidNo value / no return value()
BoolBoolean valuetrue, false
IntInteger (= Int64)42, -10
Int88-bit integer1
Int1616-bit integer1
Int3232-bit integer1
Int6464-bit integer1
FloatFloating-point number (= Float64)3.14, -0.5
Float3232-bit floating-point number3.14
Float6464-bit floating-point number3.14
CharCharacter'a', '中'
StringString"hello"
BytesRaw bytes—

These are all 15 built-in type names (() is how the Void type is written). See the authoritative table and spelling rules in Language Specification §2.1: only the capitalized spelling is valid. Names such as int / i64 / str / bool are not type names. DateTime is not a built-in name—now / parse_time in std.time return an Int timestamp (writing a bare DateTime annotation produces an unknown-type error).

Composite Types ​

TypeDescriptionExamples
Tuple(T1, T2, ...)Tuple of heterogeneous elements(1, "hello")
(Args) -> RetFunction 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), and List(T) is a standard library type ({ data: Vec(T), length: Int }, with all policies implemented in the library).

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 a newline
println(value)         // Print with a newline

Conversion ​

yaoxiang
to_string(value)       // Convert to a string
to_int(value)          // Convert to an integer
to_float(value)        // Convert to a floating-point number

Type Checking ​

yaoxiang
typeof(value)         // Return the type name
is_type(value, type)  // Check the type

Keywords ​

KeywordDescription
TypeMeta-type
spawnMarks a spawn function
spawn forParallel loop
spawn {}Spawn block
if / else if / elseConditional branches
matchPattern matching
while / forLoops
returnReturn value
refCreate a reference
mutMutable 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 + 1

Function Definition ​

yaoxiang
// 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 = x

Control Flow ​

yaoxiang
// 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 ​

yaoxiang
// The ? operator propagates errors
data = fetch_file(path)?

Operator Precedence ​

PrecedenceOperator
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 ​

yaoxiang
// 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.0

Command-Line Tools ​

bash
# 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 --help

Complete Example ​

yaoxiang
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)))
}

Contributing Guidelines ​

The standard library is under construction, and contributions are welcome!

  1. Choose a module (such as std.io or std.net)
  2. Implement functions in src/std/
  3. Add documentation comments
  4. Submit a PR