This project is a minimal Lisp interpreter written in Rust. It supports basic arithmetic operations, defining variables, and a few list manipulation functions. The interpreter can be run in an interactive mode, which allows you to enter Lisp expressions directly into the command line.
- Arithmetic operations: +, -
- Equality comparison with the = symbol
- Variable definition with define
- Printing values with print
- List manipulation with car and cdr
- Counting elements in a list
- Accumulating the sum of all values in a list
To run the interpreter, follow these steps:
- Ensure you have Rust and Cargo installed on your system. If you don't have them, follow the instructions at https://www.rust-lang.org/tools/install to install Rust and Cargo.
- Clone this repository to your local machine.
- Navigate to the project directory using the command line.
- Run the interpreter with the command cargo run.
After executing cargo run, you will enter the interactive mode, where you can type Lisp expressions directly. Press CTRL+D or CTRL+C to exit the interpreter.
Here are some examples of using the Lisp interpreter:
- Arithmetic operations:
> (+ 2 3)
5
> (* 4 (- 5 3))
8
- Defining variables
> (define a 5)
a
> (define b (+ a 3))
b
- Printing values:
> (print a)
5
> (print b)
8
- List manipulation with car and cdr:
> (car (list 1 2 3))
1
> (cdr (list 1 2 3))
(2 3)
- Equality comparison:
> (= 5 5)
true
> (= 5 6)
false
- Counting elements in a list:
> (list-length (1 2 3))
3
- Accumulating the sum of all values in a list:
> (list-sum ( 1 2 3))
6
This Lisp interpreter is minimal and lacks many features found in full-fledged Lisp dialects. It is intended primarily for educational purposes and to demonstrate Rust's capabilities in building interpreters.