A dynamic toy programming language implemented twice from scratch in Rust (./src/monkey-rs) and Go (./src/monkey-go) based on the book Writing an Interpreter in Go by Thorsten Ball
puts("hello world");//> hello worldleta=1;puts(a+1);//> 2letb=6;puts(a+b);//> 8letb=" foo";puts(4+a+b);//> 15 fooletstr="this is a string";puts(len(str));//> 16letarr=["this","is","an","array",1,true];puts(len(arr));//> 6lethsh={"this": "is","a": "hash",true: false,1: 101};puts(hsh["this"]+hsh["a"])//> ishashletfactorial=fn(n){if(n<=1){return1;}returnn*factorial(n-1);}puts(factorial(8));//> 40320letfibonacci=fn(n){if(n<=1){return1;}returnfibonacci(n-2)+fibonacci(n-1);}puts(fibonacci(25))//> 121393letarr=[0,1,2,3,5,6,7,8,9]puts(len(arr))//> 10puts(first(arr))//> 0puts(last(arr))//> 9puts(rest(arr))//> [1, 2, 3, 5, 6, 7, 8, 9]puts(push(arr,10))//> [0, 1, 2, 3, 5, 6, 7, 8, 9, 10]Returns expression as a raw AST object without evaluating (except for expressions inside unquote)
Can only be used inside quote argument
Evaluate expression or quoted AST object passed as argument
puts(quote(foobar+barfoo));//> QUOTE((foobar + barfoo))puts(quote(8+unquote(4+4)));//> QUOTE((8 + 8))letquotedInfixExpression=quote(4+4);puts(quote(unquote(4+4)+unquote(quotedInfixExpression)));//> QUOTE((8 + (4 + 4)))letunless=macro(condition,consequence,alternative){quote(if(!unquote(condition)){unquote(consequence);}else{unquote(alternative);});};unless(10>5,puts("not greater"),puts("greater"));//> greater