1. Documentation
Introduction to Braid
Braid is a high-performance, statically typed systems programming language that combines Python-like syntax, Rust-like safety, and C-like speed. It targets ML/AI workloads, systems programming, and full-stack web development.
History
Braid was created to bridge the gap between expressive high-level languages and performant low-level systems. The language evolved from a need for a unified toolchain that could handle everything from neural network training to web application development without sacrificing readability or performance. The prototype compiler (braidc) uses a C lexer/parser pipeline with a C++ IR and codegen backend.
Design Philosophy
Braid is built on three pillars:
- Python-like syntax — Readable, familiar syntax with braces
{}and semicolons; - Rust-like safety — Strong static typing with Hindley-Milner type inference, ARC with cycle detection
- C-like speed — Compilation to native code via C codegen and GCC, with bytecode VM execution
Key Features
- Strong static typing — Every value has a type known at compile time
- ARC memory management — No garbage collection pauses
- First-class tensors — N-dimensional arrays with slicing and device transfer
- Diameter construct — Dialectical programming for complex reasoning
- @autograd — Built-in automatic differentiation
- C FFI — Call C functions directly with
extern fn - Match expressions — Pattern matching on integers, strings, booleans, enums, and nil
- Bytecode VM — Compile to
.bxbytecode for portable execution
Hello World
fn main() {
print("Hello, Braid!")
}Variables and Functions
let x = 42
let name = "Braid"
let pi = 3.14
fn add(a: int, b: int) -> int {
return a + b
}
let result = add(x, 8)
print(result) // 50Tensors and ML
let matrix = [[1, 2], [3, 4]]
let val = matrix[0][1] // 2
let slice = matrix[0:2] // rows 0-1
@autograd fn loss(x: float, y: float) -> float {
return (x - y) * (x - y)
}Diameter Example
diameter temperature: {
pole hot: {
return 80.0
}
pole cold: {
return 10.0
}
}
temperature.evolve()
let tension = temperature.observe("tension")