This is a simple Scheme interpreter written in Rust.
To build the interpreter, you need to have Rust and Cargo installed. Navigate to the project directory in your terminal and run:
cargo build --release
To run the interpreter's REPL (Read-Eval-Print Loop), use:
cargo run
This will start an interactive session where you can type Scheme expressions.
To exit the REPL, press Ctrl+C
, Ctrl+D
, or type exit
and press Enter.
The interpreter currently supports a subset of Scheme, including:
- Core Forms:
define
: Define variables and functions.if
: Conditional execution.lambda
: Create anonymous functions. Example:((lambda (x) (* x x)) 5) ; Output: 25
quote
/'
: Prevent evaluation. Example:'(+ 1 2) ; Output: (+ 1 2)
- Macros (from stdlib.scm):
case
: Selects a clause based on matching a key. Example:(case (* 2 3) ((1 5 7) "odd") ((2 4 6) "even")) ; Output: "even"
let
: Bind variables locally. Example:(let ((x 1) (y 2)) (+ x y)) ; Output: 3
let*
: Sequential local binding. Example:(let* ((x 1) (y (+ x 1))) (* x y)) ; Output: 2
letrec
: Recursive local binding (for functions). Example:(letrec ((fact (lambda (n) (if (zero? n) 1 (* n (fact (- n 1))))))) (fact 5)) ; Output: 120