Stak Scheme
The miniature, embeddable R7RS Scheme implementation in Rust
Stak Scheme aims to be:
- An embeddable Scheme interpreter for Rust with very small memory footprint and reasonable performance
- The minimal implementation of the R7RS-small standard
- A subset of Chibi Scheme, Gauche, and Guile
- A portable scripting environment that supports even no-
std
and no-alloc
platforms
For more information and usage, visit the full documentation.
Install
Interpreter
To install the Scheme interpreter as a command, run:
Libraries
To install Stak Scheme as a library in your Rust project, run:
For full examples, see the examples
directory.
Examples
Dynamic scripting in Rust
First, prepare a Scheme script named src/fight.scm
:
; Import a base library and the library named `(stak rust)` for Rust integration.
(import (scheme base) (stak rust))
; Make two people with a number of pies they have and their dodge rates.
(define me (make-person 4 0.2))
(define friend (make-person 2 0.6))
; The fight begins. Let's throw pies to each other!
(do ()
((or
(person-wasted me)
(person-wasted friend)
(and
(zero? (person-pies me))
(zero? (person-pies friend)))))
(person-throw-pie me friend)
(person-throw-pie friend me))
; Output the winner.
(write-string
(cond
((person-wasted friend)
"You won!")
((person-wasted me)
"You lost...")
(else
"Draw...")))
Then, add a build script at build.rs
to build the Scheme source file
into bytecodes.
use ;
Finally, you can embed and run the Scheme script in a Rust program.
use ;
use Error;
use random;
use ;
const HEAP_SIZE: usize = 1 << 16;
/// A person who holds pies to throw.
References
- This project is based on Ribbit Scheme, the small and portable R4RS implementation.
- Scheme programming language
- The R7RS-small standard