Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

dwayne/elm-monkey-interpreter

Open more actions menu

Repository files navigation

Elm Monkey Interpreter (Playground)

A Monkey interpreter written in Elm.

Monkey is a programming language designed by Thorsten Ball that is fully described in his interpreter book.

Syntax

The syntax of Monkey is scattered throughout the pages of the book. However, I extracted a context-free grammar that you can use to learn the syntax.

let filter = fn (pred, arr) {
  let iter = fn (arr, accumulated) {
    if (len(arr) == 0) {
      accumulated
    } else {
      if (pred(first(arr))) {
        iter(rest(arr), push(accumulated, first(arr)))
      } else {
        iter(rest(arr), accumulated)
      }
    }
  };
  iter(arr, [])
};

let mod = fn (a, b) {
  a - a / b * b
};

let isEven = fn (n) {
  mod(n, 2) == 0
};

filter(isEven, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

You can also use the parser tests as a guide.

Semantics

The semantics is defined by the interpreter. You can get a sense for it by reading through the extensive suite of interpreter tests.

About

A Monkey interpreter written in Elm.

Topics

Resources

Stars

Watchers

Forks

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.