aboutsummaryrefslogtreecommitdiff
path: root/miniMAL/miniMAL-core.json
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2015-02-11 21:56:47 -0600
committerJoel Martin <github@martintribe.org>2015-02-11 21:56:47 -0600
commitc1fe72ae2b94d37cbf027aa185c27307d9776c56 (patch)
tree6826d1941743bf7d450b538bbcae86fb6749b8e9 /miniMAL/miniMAL-core.json
parentff26ebdb816da07b28b29073868994fc7eabf8d1 (diff)
downloadmal-c1fe72ae2b94d37cbf027aa185c27307d9776c56.tar.gz
mal-c1fe72ae2b94d37cbf027aa185c27307d9776c56.zip
miniMAL: step1.
Diffstat (limited to 'miniMAL/miniMAL-core.json')
-rw-r--r--miniMAL/miniMAL-core.json98
1 files changed, 98 insertions, 0 deletions
diff --git a/miniMAL/miniMAL-core.json b/miniMAL/miniMAL-core.json
new file mode 100644
index 0000000..a4acfec
--- /dev/null
+++ b/miniMAL/miniMAL-core.json
@@ -0,0 +1,98 @@
+["do",
+
+["def", "map", ["fn", ["a", "b"], [".", "b", ["`", "map"], "a"]]],
+["def", "not", ["fn", ["a"], ["if", "a", false, true]]],
+
+["def", "nil?", ["fn", ["a"], ["=", null, "a"]]],
+["def", "true?", ["fn", ["a"], ["=", true, "a"]]],
+["def", "false?", ["fn", ["a"], ["=", false, "a"]]],
+["def", "string?", ["fn", ["a"],
+ ["if", ["=", "a", null],
+ false,
+ ["=", ["`", "String"],
+ [".-", [".-", "a", ["`", "constructor"]],
+ ["`", "name"]]]]]],
+
+["def", "pr-list*", ["fn", ["a", "pr", "sep"],
+ [".", ["map", ["fn", ["x"],
+ ["if", "pr",
+ [".", "JSON", ["`", "stringify"], "x"],
+ ["if", ["string?", "x"],
+ "x",
+ [".", "JSON", ["`", "stringify"], "x"]]]],
+ "a"],
+ ["`", "join"], "sep"]]],
+["def", "pr-str", ["fn", ["&", "a"],
+ ["pr-list*", "a", true, ["`", " "]]]],
+["def", "str", ["fn", ["&", "a"],
+ ["pr-list*", "a", false, ["`", ""]]]],
+["def", "prn", ["fn", ["&", "a"],
+ [".", "console", ["`", "log"],
+ ["pr-list*", "a", true, ["`", " "]]]]],
+["def", "println", ["fn", ["&", "a"],
+ [".", "console", ["`", "log"],
+ ["pr-list*", "a", false, ["`", " "]]]]],
+
+["def", ">=", ["fn", ["a", "b"],
+ ["if", ["<", "a", "b"], false, true]]],
+["def", ">", ["fn", ["a", "b"],
+ ["if", [">=", "a", "b"], ["if", ["=", "a", "b"], false, true], false]]],
+["def", "<=", ["fn", ["a", "b"],
+ ["if", [">", "a", "b"], false, true]]],
+
+["def", "list", ["fn", ["&", "a"], "a"]],
+["def", "list?", ["fn", ["a"], [".", "Array", ["`", "isArray"], "a"]]],
+["def", "assoc!", ["fn", ["a", "b", "c"], ["do", ["set", "a", "b", "c"], "a"]]],
+["def", "assocs!", ["fn", ["hm", "kvs"],
+ ["if", ["empty?", "kvs"],
+ "hm",
+ ["do",
+ ["assoc!", "hm", ["get", "kvs", 0], ["get", "kvs", 1]],
+ ["assocs!", "hm", ["slice", "kvs", 2]]]]]],
+["def", "hash-map", ["fn", ["&", "a"],
+ ["assocs!", ["new", "Object"], "a"]]],
+["def", "get", ["fn", ["a", "b"], [".-", "a", "b"]]],
+["def", "set", ["fn", ["a", "b", "c"], [".-", "a", "b", "c"]]],
+["def", "contains?", ["fn", ["a", "b"], [".", "a", ["`", "hasOwnProperty"], "b"]]],
+["def", "keys", ["fn", ["a"], [".", "Object", ["`", "keys"], "a"]]],
+["def", "vals", ["fn", ["a"], ["map",["fn",["k"],["get","a","k"]],["keys", "a"]]]],
+
+["def", "cons", ["fn", ["a", "b"],
+ [".", ["`", []],
+ ["`", "concat"], ["list", "a"], "b"]]],
+["def", "concat", ["fn", ["&", "a"],
+ [".", [".-", ["list"], ["`", "concat"]],
+ ["`", "apply"], ["list"], "a"]]],
+["def", "nth", "get"],
+["def", "first", ["fn", ["a"], ["nth", "a", 0]]],
+["def", "rest", ["fn", ["a"], [".", "a", ["`", "slice"], 1]]],
+["def", "empty?", ["fn", ["a"], ["if", ["list?", "a"], ["if", ["=", 0, [".-", "a", ["`", "length"]]], true, false], ["=", "a", null]]]],
+["def", "count", ["fn", ["a"],
+ [".-", "a", ["`", "length"]]]],
+["def", "slice", ["fn", ["a", "start", "&", "endl"],
+ ["let", ["end", ["if", ["count", "endl"],
+ ["get", "endl", 0],
+ [".-", "a", ["`", "length"]]]],
+ [".", "a", ["`", "slice"], "start", "end"]]]],
+
+["def", "apply", ["fn", ["a", "b"], [".", "a", ["`", "apply"], "a", "b"]]],
+
+["def", "typeof", ["fn", ["a"], ["js", ["str", ["`", "typeof "], ["pr-str", "a"]]]]],
+
+["def", "repl", ["fn",["prompt", "rep"],
+ ["let", ["r", ["require", ["`", "repl"]],
+ "evl", ["fn", ["l", "c", "f", "cb"],
+ ["let", ["line", ["slice", "l", 1, ["-", [".-", "l", ["`", "length"]], 2]]],
+ ["do",
+ ["println", ["rep", "line"]],
+ ["cb"]]]],
+ "opts", {"ignoreUndefined": true,
+ "terminal": false},
+ "opts", ["assoc!", "opts", ["`", "prompt"], "prompt"],
+ "opts", ["assoc!", "opts", ["`", "eval"], "evl"]],
+ [".", "r", ["`", "start"], "opts"]]]],
+
+null
+
+]
+