Embedding Scheme in Rust

submited by
Style Pass
2025-01-08 10:00:03

Rust, as a compiled language, makes it challenging to modify the behavior of programs dynamically. In this article, we embed a small Scheme interpreter called Stak Scheme in Rust to dynamically change the behavior of a program without stopping the process.

Scheme is a functional programming language and a Lisp dialect. It is known for its simple language specification and support of the first-class continuation as a language feature. The R7RS-small standard is its latest specification available.

Stak Scheme is a Scheme implementation compatible with the R7RS-small standard. It is originally developed as a fork of Ribbit Scheme. Stak Scheme has the following features.

In this example, we will write a program of an HTTP server in Rust and embed a Scheme script in it to change the behavior of the HTTP server dynamically.

The stak crate is a library that runs the Scheme interpreter from Rust. The stak-build crate is a library that compiles Scheme scripts in build.rs build scripts (mentioned in the later section) so that you can embed them in Rust programs. The stak-compile command is a Scheme-to-bytecode compiler for Stak Scheme.

Leave a Comment