Monkey lang is interpreter programming language. It's a tree-walking interpreter
Here is what Monkey looks like:
// Integers & arithmetic expressions...
let version = 1 + (50 / 2) - (8 * 3);
// ... and strings
let name = "The Monkey programming language";
// ... booleans
let isMonkeyFastNow = true;
// ... arrays & hash maps
let people = [{"name": "Anna", "age": 24}, {"name": "Bob", "age": 99}];
It also has functions!
// User-defined functions...
let getName = fn(person) { person["name"]; };
getName(people[0]); // => "Anna"
getName(people[1]); // => "Bob"
// and built-in functions
puts(len(people)) // prints: 2
And it has conditionals, implicit and explicit returns and recursive functions, which means we can do this in Monkey:
let fibonacci = fn(x) {
if (x == 0) {
0
} else {
if (x == 1) {
return 1;
} else {
fibonacci(x - 1) + fibonacci(x - 2);
}
}
};
But the crown jewel in every Monkey implementation are closures:
// `newAdder` returns a closure that makes use of the free variables `a` and `b`:
let newAdder = fn(a, b) {
fn(c) { a + b + c };
};
// This constructs a new `adder` function:
let adder = newAdder(1, 2);
adder(8); // => 11
It has hashes
let myHash = {"name": "Jimmy", "age": 72, "band": "Led Zeppelin"};
myHash["name"] -> "Jimmy"