Files
monkey/examples/demo.monkey
Chuck Smith 6282075e66
Some checks failed
Build / build (push) Successful in 10m26s
Test / build (push) Failing after 16m44s
bind expression (:=) instead of let
2024-03-21 17:43:03 -04:00

43 lines
830 B
Plaintext

name := "Monkey";
age := 1;
inspirations := ["Scheme", "Lisp", "JavaScript", "Clojure"];
book := {
"title": "Writing A Compiler In Go",
"author": "Thorsten Ball",
"prequel": "Writing An Interpreter In Go"
};
printBookName := fn(book) {
title := book["title"];
author := book["author"];
print(author + " - " + title);
};
printBookName(book);
fibonacci := fn(x) {
if (x == 0) {
return 0
} else {
if (x == 1) {
return 1;
} else {
return fibonacci(x - 1) + fibonacci(x - 2);
}
}
};
map := fn(arr, f) {
iter := fn(arr, accumulated) {
if (len(arr) == 0) {
return accumulated
} else {
return iter(rest(arr), push(accumulated, f(first(arr))));
}
};
return iter(arr, []);
};
numbers := [1, 1 + 1, 4 - 1, 2 * 2, 2 + 3, 12 / 2];
map(numbers, fibonacci);