This is a Rust implementation of the original book Writing An Interpreter In Go, which (as you've might have guessed) is written in Go. At the moment this is a Work In Progress. The current implementation has:
- Integers, Booleans, Strings, Arrays, HashMaps
- A REPL
- Arithmetic expressions
- Let statements
- First-class and higher-order functions
- (A few) Built-in functions
- Recursion
- Closures
You can start the REPL by:
$ cargo run --release -p interpreter
Or run a Monkey program by:
$ cargo run --release -p interpreter <some-program.mnl>
let fibonacci = fn(x) {
if (x == 0) {
0
} else {
if (x == 1) {
return 1;
} else {
fibonacci(x - 1) + fibonacci(x - 2);
}
}
};
I took the liberty to change some behavior of the language.
- I don't like
puts
so we useprint
>> print("foo" + "bar")
"foobar"
- added a
insert
method for mutable hashes andarrays.
>> let map = {1: "one"};
>> map.insert(2, "two")
>> map
{1: "one", 2: "two"}