Delta456/monkey_v

Implementation of Monkey :monkey: Language in V

45

stars

50

commits

V

primary language

Aug 14, 2026

updated

interpreter
language
monkey
monkey-language
v
vlang
Browse cluster: V Language Ecosystem

README

Monkey Interpreter in V

CI

Implementation of the Monkey Programming Language in V Programming Language, following Writing An Interpreter In Go book.

It includes the full language: integers, floats, booleans, strings, arrays, hashes, first-class and higher-order functions, closures, a builtin function library (len, first, last, rest, push, puts), and the book's quote/unquote macro system.

Installation

Requires the V compiler.

git clone https://github.com/Delta456/monkey_v
cd monkey_v
v build .

Usage

Run a Monkey script:

v run main.v examples/fibonacci.monkey

Or start the REPL (no arguments):

v run main.v

Syntax

// integers, floats, booleans, strings
let age = 30;
let price = 9.99;
let name = "Monkey";
let active = true;

// arrays and hashes
let numbers = [1, 2, 3, 4];
let person = {"name": "Alice", "age": 30};
numbers[0];       // 1
person["name"];   // "Alice"

// first-class functions and closures
let newAdder = fn(x) {
  fn(y) { x + y };
};
let addTwo = newAdder(2);
addTwo(3); // 5

// recursion
let fibonacci = fn(x) {
  if (x < 2) {
    x
  } else {
    fibonacci(x - 1) + fibonacci(x - 2)
  }
};

// builtins: len, first, last, rest, push, puts
let map = fn(arr, f) {
  let iter = fn(arr, accumulated) {
    if (len(arr) == 0) {
      accumulated
    } else {
      iter(rest(arr), push(accumulated, f(first(arr))));
    }
  };
  iter(arr, []);
};
map(numbers, fn(x) { x * 2 }); // [2, 4, 6, 8]

// quote/unquote macros
let unless = macro(condition, consequence, alternative) {
  quote(
    if (!(unquote(condition))) {
      unquote(consequence);
    } else {
      unquote(alternative);
    }
  );
};
unless(10 > 5, puts("not greater"), puts("greater")); // "greater"

Examples

More complete programs live in examples/:

ScriptDemonstrates
fibonacci.monkeyRecursion
closures_and_arrays.monkeyClosures, arrays, map via builtins
higher_order_functions.monkeymap/reduce/filter built from scratch
hashes_and_strings.monkeyHash literals/indexing, string concatenation
quicksort.monkeyRecursive sorting, array filtering/concatenation
error_handling.monkeyEarly returns and runtime error objects
macros.monkeyThe quote/unquote macro system

Testing

v test .

Project layout

ModuleDescription
tokenToken types
lexerHand-written lexer
astAST node types (V sum types) and the modify tree-walker
parserPratt parser
objectRuntime object system and Environment
evalTree-walking evaluator, builtins, and the macro system
replInteractive REPL
examplesSample .monkey scripts

License

Licensed under MIT.

Contributors

Delta456

31 commits

LouisSchmieder

11 commits

dhonx

7 commits

hachi8833

1 commits

Delta456/monkey_v

Implementation of Monkey :monkey: Language in V

45

stars

50

commits

V

primary language

Aug 14, 2026

updated

interpreter
language
monkey
monkey-language
v
vlang
Browse cluster: V Language Ecosystem

README

Monkey Interpreter in V

CI

Implementation of the Monkey Programming Language in V Programming Language, following Writing An Interpreter In Go book.

It includes the full language: integers, floats, booleans, strings, arrays, hashes, first-class and higher-order functions, closures, a builtin function library (len, first, last, rest, push, puts), and the book's quote/unquote macro system.

Installation

Requires the V compiler.

git clone https://github.com/Delta456/monkey_v
cd monkey_v
v build .

Usage

Run a Monkey script:

v run main.v examples/fibonacci.monkey

Or start the REPL (no arguments):

v run main.v

Syntax

// integers, floats, booleans, strings
let age = 30;
let price = 9.99;
let name = "Monkey";
let active = true;

// arrays and hashes
let numbers = [1, 2, 3, 4];
let person = {"name": "Alice", "age": 30};
numbers[0];       // 1
person["name"];   // "Alice"

// first-class functions and closures
let newAdder = fn(x) {
  fn(y) { x + y };
};
let addTwo = newAdder(2);
addTwo(3); // 5

// recursion
let fibonacci = fn(x) {
  if (x < 2) {
    x
  } else {
    fibonacci(x - 1) + fibonacci(x - 2)
  }
};

// builtins: len, first, last, rest, push, puts
let map = fn(arr, f) {
  let iter = fn(arr, accumulated) {
    if (len(arr) == 0) {
      accumulated
    } else {
      iter(rest(arr), push(accumulated, f(first(arr))));
    }
  };
  iter(arr, []);
};
map(numbers, fn(x) { x * 2 }); // [2, 4, 6, 8]

// quote/unquote macros
let unless = macro(condition, consequence, alternative) {
  quote(
    if (!(unquote(condition))) {
      unquote(consequence);
    } else {
      unquote(alternative);
    }
  );
};
unless(10 > 5, puts("not greater"), puts("greater")); // "greater"

Examples

More complete programs live in examples/:

ScriptDemonstrates
fibonacci.monkeyRecursion
closures_and_arrays.monkeyClosures, arrays, map via builtins
higher_order_functions.monkeymap/reduce/filter built from scratch
hashes_and_strings.monkeyHash literals/indexing, string concatenation
quicksort.monkeyRecursive sorting, array filtering/concatenation
error_handling.monkeyEarly returns and runtime error objects
macros.monkeyThe quote/unquote macro system

Testing

v test .

Project layout

ModuleDescription
tokenToken types
lexerHand-written lexer
astAST node types (V sum types) and the modify tree-walker
parserPratt parser
objectRuntime object system and Environment
evalTree-walking evaluator, builtins, and the macro system
replInteractive REPL
examplesSample .monkey scripts

License

Licensed under MIT.

Contributors

Delta456

31 commits

LouisSchmieder

11 commits

dhonx

7 commits

hachi8833

1 commits

Languages

V

99.9%