Home

Awesome

rust-lisp Build Status

Rust is my new favorite language and I've really wanted to use it in a project. I like languages so I wrote a minimal Lisp-like interpreter. It draws heavy inspiration from both Common Lisp and Scheme.

Building and running

This project builds using Cargo. To build, clone this repository and run

cargo build
./target/rust-lisp

or, simply,

cargo run

cargo test will run the tests, and cargo bench will run the benchmarks

Features

This lisp interpreter draws its heaviest inspiration from Scheme and most of its feature come directly from it.

Fundamental Forms

This interpreter has ten fundamental forms as of right now:

if    defun    defmacro  define  lambda
quote unquote  and       or      quasiquote

defun will be a macro in the future. Each one of these represents a fundamental feature of this lisp:

Multiple evaluation

This interpreter will evaluate every form that it is given. As an example:

lisp> (+ 1 2) (+ 3 4) (+ 5 6)
$0 = 3
$1 = 7
$2 = 11

In the future these $x variables may be bound to the current environment, but they aren't right now.

Nil vs Empty List

This interpreter takes the side of Scheme on the nil vs empty list debate. nil is an ordinary symbol and carries no extra meaning. The empty list is written as '(), as in Scheme, and means the same thing:

lisp> (cdr '(1))
$0 = ()

Attempting to evaluate an unquoted () will result in an error.

Improper parameter lists

Improper lists can be used as the parameter form in a lambda, defun, or defmacro. An improper list binds all remaining parameters to the final parameter. As an example,

lisp> (defun test (first second third . rest) rest)
$0 = <function>

This defines a function that takes three or more parameters. The first parameter is always bound to first, the second to second, and the third to third. If there are more than three parameters, the remaining parameters are bound as a list to rest. For example,

lisp> (test 1 2 3 4 5)
$0 = (4 5)

When there are exactly as many parameters as there are required parameters, the rest parameter is the null list. For example,

lisp> (test 1 2 3)
$0 = ()

TODO list

Rust is awesome!