Orangutan is a minimal, dynamically-typed, interpreted language with a C-like syntax. Orangutan is a port of the Monkey language designed by Thorsten Ball in his Writing an Interpreter in Go to TypeScript and is hosted on the Deno runtime.
Great question! There isn't a lot of good reason to use Orangutan so much as there is to participate in it's development.
Orangutan is a toy language with no ecosystem as such it is the perfect base to start building from.
-
Variable assignment
let five = 5; -
Arrays
let arr = [1,2,3]; arr[0]; // 1 -
Hashes
let hash = { "language": "orangutan" }; hash["language"]; // "orangutan" -
Function definition with optionally implicit return of final expression evaluation.
let add = fn(a, b) { a + b; } -
First-class functions
let twice = fn(f, x) { return f(f(x)); }
Orangutan deviates from the canonical implementation of Monkey as follows:
- The
pushfunction on an array is renamed toappendas Orangutan also supports aprependfunction
split(str, on)splits a stringstrinto an array of strings on instances ofonlen(str)returns the length of a string
join(arr, using)joins an arrayarrof strings usingusingbetween array items.map(arr, fn)filter(arr, fn)reduce(arr, fn)zip(arrOne, arrTwo)joins items from two arrays, joining on index, returning an array of two-item arrays as long as the shortest ofarrOneandarrTwozipLongest(arrOne, arrTwo, optionalDefaultValue)same as zip but returns an array the same length as the longer ofarrOneandarrTwowith holes filled withnulloroptionalDefaultValueif supplied.
entries(hash)returns an array of two-item arrays each representing the key, and value of each entry inhash.keys(hash)returns an array comprised of each key inhash.values(hash)returns an array comprised of each value inhash.
readFile(path)reads the content of a file into a StringwriteFile(path, str)writesstrto a file atpath
get(url)returns the body of an HTTP GET request tourlas a Stringpost(url, str)postsstras the body of an HTTP POST request tourl.
type(obj)returns the type ofobjprompt()prompts user for inputffi(javascriptString)is an experimental feature that passesjavascriptStringdown to the Deno runtime to evaluate.
- A
Numbertype, distinct from the basicMonkeytype (which ultimately resolves to a javascriptNumbertype) - Variable reassignment across scopes
- The
use(filePath)function for importing code from other files - Hashes can be used as indices to Hashes (this was added as a requirement to realise Orangutan Monkey Interpreter)
- First ensure Deno is installed. Last tested on
deno 2.0.6 (stable, release, x86_64-pc-windows-msvc) - Then just clone the repository:
git clone https://github.com/emilkloeden/orangutan.git - (Optionally) compile the binary with:
deno compile -A -o <destination_path> .\src\index.ts
$ deno run --allow-all=. .\index.ts
Orangutan REPL. Press Ctrl+c or type exit() to quit.
>(or if orangutan is compiled and added to your PATH variable)
$ orangutan$ deno run --allow-all=. .\index.ts run <my_script.utan>(or if orangutan is compiled and added to your PATH variable)
$ orangutan run- A language server
- A package manager
