Lisp in the Rust Type System
Summary
A Lisp interpreter embedded in Rust's trait system, allowing recursive functions, closures, and continuation passing style at compile time.
View Cached Full Text
Cached at: 06/22/26, 07:31 AM
playX18/lisp-in-types
Source: https://github.com/playX18/lisp-in-types
lisp-in-types
Lisp in Rust trait system.
Limitations
- Each symbol must be manually declared via
defkey!()macro - Numbers cannot be negative
- Numbers are only in range of 0..8192, you can modify build.rs to generate more natural numbers but then you have to run with RUST_MIN_STACK increased.
- No
(defmacro ...) - No
eval - I have not tested it extensively.
Features
- Recursive functions
- Global and lexical environments (via
letbindings) - Function calls
applyproperly workingcall/ec
Example
Factorial:
type DefFac = expr!(defun SymFac (SymN) (if (= SymN 0) 1 (* SymN (SymFac (- SymN 1)))));
type Global2 = <DefFac as EvalForm<Global1, Lex0>>::GlobalOut;
type Fac5 = EvalValue<expr!((SymFac 5)), Global2, Lex0>;
assert_same::<Fac5, N120>();
println!("(fac 5) => {:?}", <Fac5 as ToRtValue>::to_rt());
call/ec (delimited)
// call/ec demo (escape continuation, explicit tag):
// (call/ec cc (lambda (k) (+ 1 (k 5)))) => 5
defkey!(SymCC, N10);
defkey!(SymK, N11);
type CallECExpr = expr!((call/ec SymCC (lambda (SymK) (+ 1 (SymK 5)))));
type CallECResult = EvalValue<CallECExpr, Global1, Lex0>;
assert_same::<CallECResult, N5>();
println!(
"(call/ec cc (lambda (k) (+ 1 (k 5)))) => {:?}",
<CallECResult as ToRtValue>::to_rt()
);
Similar Articles
RISC-V interpreter from the future
An update to a RISC-V interpreter in Rust, featuring modularity, no_std support, compile-time execution, and strict specification compliance, utilizing many nightly Rust features.
Tail-Call Interpreters in Rust – Jimmy Ostler
Jimmy Ostler explores tail-call interpreters in Rust, implementing and benchmarking various VM dispatch techniques including switch dispatch, subroutine threading, and tail-call optimized machines.
Lisp's Influence on Ruby
A technical blog post exploring how Ruby's design, including closures, first-class functions, symbols, and method naming conventions, was influenced by Lisp.
Why building a Rust LSP is hard
The blog post explains the technical challenges of building a Language Server Protocol for Rust, drawing from the author's experience with Rust Glancer and insights from rust-analyzer.
Port of the TypeScript compiler, checker and lsp to Rust, by LLM
A project demonstrates porting Microsoft's TypeScript compiler, checker, and LSP to Rust entirely using LLMs — Anthropic's Opus 5.5 rewrote the codebase from scratch in about $24k of API spend, achieving full compatibility with real-world projects as an early-release drop-in `tsc-rs` replacement.