A basic Lisp interpreter built in Rust. Try it at lisper.victr.com.
This is a project to explore Rust and WebAssembly, inspired by the great work done by Stepan Parunashvili and the original post from Peter Norvig. There is also a fair bit of foundational curiosity that came from playing around with Ronin, by the always interesting Hundred Rabbits.
The project has four parts:
- The lisper lib - the core functionality of the lisp interpreter
- REPL app - a command line interface for lisper
- WASM lib - that packages the lib as a redy to be used WASM module
- A web app - a Next.js app that offers a Lisp editor, using the WASM module
It probably isn't the best idea to have all this in one repo, but for now it allows for fast iteration on the various interdependant parts locally and deployed. Uses Github Actions to automatically build, run tests, and delpoy to Vercel.
Just clone the repo and get going, there are no dependencies beyond rust and cargo.
To build and run:
$ cargo run
Launches the REPL.
To run the tests:
$ cargo test
Lisper environment functions These are the currently defined functions implemented for Lisper, more to come.
Function | Example |
---|---|
+ | (+ x y) |
- | (- x y) |
* | (\* x y) |
/ | (/ x y) |
% | (% x y) |
sin | (sin x) |
cos | (cos x) |
tan | (tan x) |
< | (< x y) |
> | (> x y) |
<= | (<= x y) |
>= | (>= x y) |
All functions currently take n amount of arguments, e.g. (+ 1 1 1 1 1 ...).
Predefined constants
Value | Constants |
---|---|
ฯ | pi |
ฯ * 2 | two_pi |
e | e |
def
Format: (def name value_exp)
- name - Can be any string and non-numeric character
- There is no validation of not being able to overwrite existing defined functions or constants
- value_exp - Any valid Lisper expression that resolves to a value
All defined values and functions are global within the current and inherited scopes.
if
Format: (if if_evaluation_expr true_value false_value)
- if_evaluation_expr - Any Lisper expression that evaluates to a number or bool
- true_value - Any valid Lisper expression that resolves to a value
- false_value - Any valid Lisper expression that resolves to a value
fn
Format: (fn fn_name argument_name(s) function_exp)
- fn_name - Can be any string and non-numeric character
- There is no validation of not being able to overwrite existing defined functions or constants
- argument_name - Can be any string and non-numeric character
- There is no validation of not being able to overwrite existing defined functions or constants
- There can be 1 to n named arguments.
- function_exp - Any valid Lisper expression that resolves to a value
Lambda functions execute within it's own scoped environment, inheriting from the parent environment. All defined values and functions are global within the current and inherited scopes.