lua-monkey is a lua implementation of a tree-walking interpreter for Monkey.
My monkey implementation has been extended to support the following new features:
-
Friendly error messages that display the offending line of code and underline the exact location of the error.
-
arrow functions e.g
let adder = fn x => fn y => x+y; adder(1)(2)let adder = fn(x,y)=> x+y -
Default parameters
let add = fn (x,y=1) => x+y; add(1); //2 add(10,90); //100 -
for in loops
for(item,index in [1,2,3,4]){ puts(item+index)} -
Ability to run monkey files (.mo extension)
-
comments (both single and multi line)
// a comment!/* a multiline comment */ -
Logical OR and logical AND operators
-
<= and >= operators
-
% operator
-
String comparison
-
String indexing
-
more builtin functions
- map
map([1,2,3,4], fn x => x*2) - find
find(["hello", "world"], fn w => w=="hello") - reduce
reduce([1,2,3,4], fn(acc,curr) => acc+curr,100) - filter
filter([1,2,3,4], fn x => x%2==0) - set
let map = { "a": 1 }; set(map,"b",2); map["b"] //2
- map
Clone the project
git clone https://github.com/michaelbdev/lua-monkeyGo to the project directory
cd lua-monkeyInstall dependencies
luarocks install --only-deps lua-monkey-0.1.0-1.rockspec lua main.lua --repl lua main.lua busted tests