aboutsummaryrefslogtreecommitdiff
path: root/miniMAL/core.json
diff options
context:
space:
mode:
Diffstat (limited to 'miniMAL/core.json')
-rw-r--r--miniMAL/core.json154
1 files changed, 154 insertions, 0 deletions
diff --git a/miniMAL/core.json b/miniMAL/core.json
new file mode 100644
index 0000000..164a846
--- /dev/null
+++ b/miniMAL/core.json
@@ -0,0 +1,154 @@
+["do",
+
+["def", "_path", ["require", ["`", "path"]]],
+
+["def", "_node_readline", ["require", [".", "_path", ["`", "resolve"],
+ ["`", "."],
+ ["`", "node_readline.js"]]]],
+
+["def", "div", ["fn", ["a", "b"], ["parseInt", ["/", "a", "b"]]]],
+
+["def", "time-ms", ["fn", [],
+ [".", ["new", "Date"], ["`", "getTime"]]]],
+
+
+["def", "assoc", ["fn", ["src-hm", "&", "kvs"],
+ ["let", ["hm", ["clone", "src-hm"]],
+ ["assocs!", "hm", "kvs"]]]],
+
+["def", "dissoc", ["fn", ["src-hm", "&", "ks"],
+ ["let", ["hm", ["clone", "src-hm"]],
+ ["do",
+ ["map", ["fn", ["k"], ["del", "hm", "k"]], "ks"],
+ "hm"]]]],
+
+["def", "_get", ["fn", ["obj", "key"],
+ ["if", ["nil?", "obj"],
+ null,
+ ["if", ["contains?", "obj", "key"],
+ ["get", "obj", "key"],
+ null]]]],
+
+["def", "_count", ["fn", ["a"],
+ ["if", ["=", null, "a"],
+ 0,
+ ["count", "a"]]]],
+
+["def", "_nth", ["fn", ["seq", "idx"],
+ ["if", [">=", "idx", ["count", "seq"]],
+ ["throw", "nth: index out of range"],
+ ["nth", "seq", "idx"]]]],
+
+["def", "_first", ["fn", ["seq"],
+ ["if", ["empty?", "seq"],
+ null,
+ ["first", "seq"]]]],
+
+["def", "_apply", ["fn", ["f", "&", "args"],
+ ["let", ["fn", ["if", ["malfunc?", "f"], ["get", "f", ["`", "fn"]], "f"],
+ "fargs", ["concat", ["slice", "args", 0, ["-", ["count", "args"], 1]],
+ ["nth", "args", ["-", ["count", "args"], 1]]]],
+ ["apply", "fn", "fargs"]]]],
+
+["def", "_map", ["fn", ["f", "seq"],
+ ["let", ["fn", ["if", ["malfunc?", "f"], ["get", "f", ["`", "fn"]], "f"]],
+ ["map", "fn", "seq"]]]],
+
+["def", "with_meta", ["fn", ["obj", "m"],
+ ["let", ["new-obj", ["clone", "obj"]],
+ ["do",
+ ["set", "new-obj", ["`", "__meta__"], "m"],
+ "new-obj"]]]],
+
+["def", "meta", ["fn", ["obj"],
+ ["if", ["or", ["sequential?", "obj"],
+ ["map?", "obj"],
+ ["malfunc?", "obj"]],
+ ["if", ["contains?", "obj", ["`", "__meta__"]],
+ ["get", "obj", ["`", "__meta__"]],
+ null],
+ null]]],
+
+["def", "reset!", ["fn", ["atm", "val"],
+ ["set", "atm", ["`", "val"], "val"]]],
+
+["def", "swap!", ["fn", ["atm", "f", "&", "args"],
+ ["let", ["fn", ["if", ["malfunc?", "f"], ["get", "f", ["`", "fn"]], "f"],
+ "fargs", ["cons", ["get", "atm", ["`", "val"]], "args"],
+ "val", ["apply", "fn", "fargs"]],
+ ["do",
+ ["set", "atm", ["`", "val"], "val"],
+ "val"]]]],
+
+["def", "core-ns",
+ ["hash-map",
+ ["`", "="], "equal?",
+ ["`", "throw"], "throw",
+
+ ["`", "nil?"], "nil?",
+ ["`", "true?"], "true?",
+ ["`", "false?"], "false?",
+ ["`", "symbol"], "symbol",
+ ["`", "symbol?"], "symbol?",
+ ["`", "keyword"], "keyword",
+ ["`", "keyword?"], "keyword?",
+
+ ["`", "pr-str"], ["fn", ["&", "a"], ["pr-list", "a", true, ["`", " "]]],
+ ["`", "str"], ["fn", ["&", "a"], ["pr-list", "a", false, ["`", ""]]],
+ ["`", "prn"], ["fn", ["&", "a"],
+ ["do",
+ ["println", ["pr-list", "a", true, ["`", " "]]],
+ null]],
+ ["`", "println"], ["fn", ["&", "a"],
+ ["do",
+ ["println", ["pr-list", "a", false, ["`", " "]]],
+ null]],
+ ["`", "read-string"], "read-str",
+ ["`", "readline"], ["fn", ["p"],
+ [".", "_node_readline", ["`", "readline"], "p"]],
+ ["`", "slurp"], "slurp",
+
+ ["`", "<"], "<",
+ ["`", "<="], "<=",
+ ["`", ">"], ">",
+ ["`", ">="], ">=",
+ ["`", "+"], "+",
+ ["`", "-"], "-",
+ ["`", "*"], "*",
+ ["`", "/"], "div",
+ ["`", "time-ms"], "time-ms",
+
+ ["`", "list"], "list",
+ ["`", "list?"], "list?",
+ ["`", "vector"], "vector",
+ ["`", "vector?"], "vector?",
+ ["`", "hash-map"], "hash-map",
+ ["`", "assoc"], "assoc",
+ ["`", "dissoc"], "dissoc",
+ ["`", "map?"], "map?",
+ ["`", "get"], "_get",
+ ["`", "contains?"], "contains?",
+ ["`", "keys"], "keys",
+ ["`", "vals"], "vals",
+
+ ["`", "sequential?"], "sequential?",
+ ["`", "cons"], "cons",
+ ["`", "concat"], "concat",
+ ["`", "nth"], "_nth",
+ ["`", "first"], "_first",
+ ["`", "rest"], ["fn", ["a"], ["rest", "a"]],
+ ["`", "empty?"], "empty?",
+ ["`", "count"], "_count",
+ ["`", "apply"], "_apply",
+ ["`", "map"], "_map",
+ ["`", "conj"], null,
+
+ ["`", "with-meta"], "with_meta",
+ ["`", "meta"], "meta",
+ ["`", "atom"], "atom",
+ ["`", "atom?"], "atom?",
+ ["`", "deref"], ["fn", ["a"], ["get", "a", ["`", "val"]]],
+ ["`", "reset!"], "reset!",
+ ["`", "swap!"], "swap!"]],
+
+null]