Lambdust (λust) - Rust Scheme Interpreter
Lambdust is a complete R7RS Scheme interpreter implemented in Rust, designed for embedding in applications as a macro and scripting system. The name combines "lambda" (λ) with "Rust," reflecting Scheme's functional nature and the ability to add expressive power to existing applications.
Features
- R7RS Compliance: Implements the R7RS Small language specification
- Embedded Design: Designed for integration into Rust applications
- Macro System: Full support for Scheme's powerful macro system
- Type Safety: Leverages Rust's type system for memory safety
- Bridge API: Seamless interoperability between Rust and Scheme
- Performance: Optimized for speed with tail-call optimization
Quick Start
Add Lambdust to your Cargo.toml:
[]
= "0.1.0"
Basic Usage
use Interpreter;
Advanced Integration with Bridge API
use ;
Architecture
The interpreter consists of several key components:
- Lexer: Tokenizes Scheme source code
- Parser: Builds Abstract Syntax Trees (AST) from tokens
- Evaluator: Executes Scheme expressions with proper semantics
- Environment: Manages variable bindings and lexical scoping
- Macro System: Handles macro expansion and transformation
- Bridge: Provides interoperability with external Rust code
Supported Scheme Features
- All basic data types (numbers, strings, symbols, lists, etc.)
- Special forms (
define,lambda,if,cond,let, etc.) - First-class procedures and closures
- Tail-call optimization
- Macro system with built-in macros (
let,cond,case, etc.) - Proper lexical scoping
- Built-in procedures for list manipulation, arithmetic, etc.
Built-in Procedures
Arithmetic Operations
+,-,*,/: Basic arithmetic=,<,>,<=,>=: Numeric comparisonsabs,floor,ceiling,round,sqrt: Math functions
List Operations
car,cdr,cons: Basic list operationslist,length,append,reverse: List construction and manipulationmap,filter,fold-left,fold-right: Higher-order functions
Type Predicates
number?,string?,symbol?,list?,pair?,null?boolean?,procedure?
String Operations
string-length,string-append,substringstring=?,string<?,string>?
I/O Operations
display,newline,read
Bridge API
The Bridge API enables seamless integration between Rust and Scheme code:
Type Conversion
Implement ToScheme and FromScheme traits for automatic type conversion:
use ;
// Custom type conversion
External Functions
Register Rust functions to be callable from Scheme:
bridge.register_function;
Object Management
Register and manipulate Rust objects from Scheme:
let counter = Counter ;
let counter_id = bridge.register_object;
bridge.define;
Examples
See the examples/ directory for complete examples:
bridge_example.rs: Demonstrates Bridge API usage- Basic arithmetic and list operations
- Function definitions and macro usage
- External object integration
Documentation
Complete API documentation is available at docs.rs/lambdust.
Building from Source
Running Tests
Generating Documentation
Development Plan
The development follows a systematic approach as documented in CLAUDE.md:
- ✅ Phase 1: Core interpreter (lexer, parser, evaluator)
- ✅ Phase 2: Built-in functions and macro system
- ✅ Phase 3: Bridge API and external integration
- 🔄 Phase 4: Advanced features and optimization
- 🔄 Phase 5: Documentation and ecosystem
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Acknowledgments
- Built with R7RS Scheme specification compliance in mind
- Inspired by the elegance of Scheme and the power of Rust
- Special thanks to the Rust and Scheme communities
Lambdust - Adding λ-powered expressiveness to Rust applications.