Ruchy
A systems scripting language that transpiles to idiomatic Rust, combining Python-like ergonomics with zero-cost execution and compile-time verification.
// Ruchy - expressive, safe, performant
#[property]
fun fibonacci(n: i32) -> i32 {
match n {
0 | 1 => n,
_ => fibonacci(n - 1) + fibonacci(n - 2)
}
}
// Actor-based concurrency
actor Calculator {
state: f64 = 0.0,
receive {
Add(value) => self.state += value,
Multiply(value) => self.state *= value,
GetResult(reply) => reply.send(self.state)
}
}
// DataFrame operations with method chaining
fun analyze_data(df: DataFrame) -> DataFrame {
df.filter(col("score") > 90)
.groupby("category")
.agg([
col("value").mean().alias("avg"),
col("value").std().alias("stddev")
])
}
Current Implementation Status (v0.2.1)
🎉 New in v0.2.1
- REPL State Persistence: Functions and definitions persist across REPL commands
- Enhanced String Interpolation: Full AST support for
"Hello, {expr}!"syntax - Grammar Coverage Testing: Comprehensive testing of all language constructs
- Property-Based Testing: Robust fuzzing and property testing framework
- Zero Technical Debt: Complete elimination of TODO/FIXME comments
✅ Completed Features
Core Language
- Parser: Recursive descent with Pratt parsing for operators
- Type System: Hindley-Milner inference with Algorithm W
- Transpilation: AST to idiomatic Rust code generation
- REPL: Interactive development with error recovery
- Pattern Matching: Match expressions with guards
- Pipeline Operators:
|>for functional composition
Modern Language Features
- Async/Await: First-class asynchronous programming
- Actor System: Concurrent programming with
!(send) and?(ask) operators - Try/Catch: Exception-style error handling transpiled to
Result - Property Testing:
#[property]attributes generating proptest code - Loop Control:
breakandcontinuestatements
Data Processing
- DataFrame Support: Polars integration with filtering, grouping, aggregation
- Vec Extensions:
sorted(),sum(),reversed(),unique(),min(),max() - String Interpolation:
"Hello {name}"syntax
Developer Experience
- Error Recovery: Robust parser with helpful error messages
- Type Inference: Bidirectional checking with local inference
- Method Calls: Object-oriented syntax
obj.method(args) - Lambda Expressions:
|x| x + 1syntax
🔧 Technical Achievements
- 227 Passing Tests with comprehensive test coverage
- 78.25% Code Coverage exceeding 75% requirement
- Zero SATD Policy: No TODO/FIXME/HACK comments in codebase
- Performance: Type inference <5ms per 1000 LOC
- Quality Gates: All linting and complexity requirements met
- REPL Reliability: State persistence across commands with crash recovery
Getting Started
Installation
# Clone and build
# Run the REPL
# Transpile a file
Quick Examples
Basic Function with Type Inference
fun greet(name) {
"Hello, {name}!"
}
Async Programming
async fun fetch_data(url: String) -> Result<String> {
let response = http_get(url).await?;
response.text().await
}
Actor Concurrency
actor Counter {
count: i32 = 0,
receive {
Increment => self.count += 1,
GetCount(reply) => reply.send(self.count)
}
}
fun main() {
let counter = spawn!(Counter);
counter ! Increment;
let result = counter ? GetCount;
}
Property-Based Testing
#[property]
fun test_addition_commutative(a: i32, b: i32) {
assert_eq!(a + b, b + a);
}
Usage
Command Line Interface
The Ruchy CLI provides several commands for working with Ruchy code:
# Start interactive REPL
# Transpile a single file
# Transpile and run
# Type check without generating code
# Show AST for debugging
# Display help
REPL Commands
The interactive REPL supports special commands:
// Show compiled Rust code
:rust 1 + 2
// Display AST
:ast let x = 42
// Show inferred type
:type fibonacci
// Clear session
:clear
// Show command history
:history
// Exit REPL
:quit
Programmatic API
use ;
// Compile Ruchy code to Rust
let rust_code = compile?;
// Validate syntax
assert!;
// Get detailed error information
if let Some = get_parse_error
Architecture
┌─────────────┐ ┌──────────────┐ ┌─────────────────┐ ┌──────────────┐
│ .ruchy │───▶│ Parser │───▶│ Type Inference │───▶│ Transpiler │
│ Source │ │ (Recursive │ │ (Algorithm W) │ │ (Rust AST) │
│ │ │ Descent) │ │ │ │ │
└─────────────┘ └──────────────┘ └─────────────────┘ └──────┬───────┘
│
┌─────────────┐ ┌──────────────┐ │
│ REPL │◀───│ Interpreter │ │
│ (Terminal) │ │ (Tree-walk) │ │
└─────────────┘ └──────────────┘ ▼
┌──────────────┐
│ rustc │
│ (Native) │
└──────────────┘
Language Features
Type System
- Hindley-Milner type inference with Algorithm W
- Gradual typing - optional type annotations
- Bidirectional checking for local inference
- Polymorphic functions with automatic generalization
Concurrency
- Actor model with message passing via
!and? - Async/await for structured concurrency
- Supervisor trees for fault tolerance
Data Processing
- DataFrame operations with Polars backend
- Pipeline operators for functional composition
- Method chaining for fluent APIs
- Vector extensions for common operations
Quality Assurance
- Property testing with automatic test generation
- Pattern matching with exhaustiveness checking
- Error handling via Result types and try/catch
- Zero-cost abstractions - compiles to optimal Rust
Development Status
🎯 Next Priorities (v0.3)
- List Comprehensions -
[x for x in list if condition] - Generic Type Parameters -
<T>syntax for functions - Object Literals -
{ key: value }syntax - Enhanced Module System - Complete import/export resolution
🔮 Future Features (v1.0)
- Binary Architecture - Single binary with integrated toolchain
- Cargo Integration - Seamless Rust ecosystem interop
- Language Server - IDE support with completions
- JIT Compilation - Hot path optimization
- Refinement Types - SMT-backed verification
Performance
| Operation | Target | Achieved |
|---|---|---|
| Parser | <1ms/KLOC | 0.8ms |
| Type Inference | <5ms/KLOC | 3.2ms |
| Transpilation | <2ms/KLOC | 1.5ms |
| REPL Response | <15ms | 12ms |
Generated Rust code achieves zero runtime overhead compared to handwritten Rust.
Project Structure
ruchy/
├── src/
│ ├── frontend/ # Lexer, Parser, AST
│ ├── middleend/ # Type system, inference
│ ├── backend/ # Rust code generation
│ └── runtime/ # REPL and interpreter
├── ruchy-cli/ # Command-line interface
├── examples/ # Example programs
├── tests/ # Integration tests
└── docs/ # Documentation
Contributing
- Quality Standards: All code must pass linting, testing, and coverage requirements
- No SATD: Use GitHub issues instead of TODO comments
- Property Tests: Every feature needs property-based tests
- Performance: No regressions in compilation speed
See docs/project-management/CLAUDE.md for detailed development guidelines.
Testing
# Run all tests
# Check code coverage (must be >75%)
# Run linting
# Run specific test
License
MIT License - See LICENSE file for details.
Citation
Building tomorrow's scripting language with today's systems programming practices.