mirror of
https://github.com/kanaka/mal.git
synced 2024-09-20 01:57:09 +03:00
6791e640e1
Issue #166.
186 lines
5.4 KiB
JSON
186 lines
5.4 KiB
JSON
["do",
|
|
|
|
["def", "_path", ["require", ["`", "path"]]],
|
|
|
|
["def", "_node_readline", ["require", [".", "_path", ["`", "resolve"],
|
|
["`", "."],
|
|
["`", "node_readline.js"]]]],
|
|
|
|
["def", "_string?", ["fn", ["s"],
|
|
["and", ["string?", "s"],
|
|
["not", ["=", ["`", "\u029e"], ["get", "s", 0]]]]]],
|
|
|
|
["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", "_rest", ["fn", ["seq"],
|
|
["if", ["empty?", "seq"],
|
|
["`", []],
|
|
["rest", "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", "_conj", ["fn", ["seq", "&", "a"],
|
|
["if", ["list?", "seq"],
|
|
[".", [".", "a", ["`", "reverse"]], ["`", "concat"], "seq"],
|
|
["vectorl", [".", "seq", ["`", "concat"], "a"]]]]],
|
|
|
|
["def", "_seq", ["fn", ["obj"],
|
|
["if", ["list?", "obj"],
|
|
["if", [">", ["count", "obj"], 0], "obj", null],
|
|
["if", ["vector?", "obj"],
|
|
["if", [">", ["count", "obj"], 0], ["slice", "obj", 0], null],
|
|
["if", ["string?", "obj"],
|
|
["if", [">", ["count", "obj"], 0],
|
|
[".", "obj", ["`", "split"], ["`", ""]],
|
|
null],
|
|
["if", ["nil?", "obj"],
|
|
null,
|
|
["throw", "seq: called on non-sequence"]
|
|
]]]]]],
|
|
|
|
["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?",
|
|
["`", "string?"], "_string?",
|
|
["`", "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"], "_rest",
|
|
["`", "empty?"], "empty?",
|
|
["`", "count"], "_count",
|
|
["`", "apply"], "_apply",
|
|
["`", "map"], "_map",
|
|
|
|
["`", "conj"], "_conj",
|
|
["`", "seq"], "_seq",
|
|
|
|
["`", "with-meta"], "with_meta",
|
|
["`", "meta"], "meta",
|
|
["`", "atom"], "atom",
|
|
["`", "atom?"], "atom?",
|
|
["`", "deref"], ["fn", ["a"], ["get", "a", ["`", "val"]]],
|
|
["`", "reset!"], "reset!",
|
|
["`", "swap!"], "swap!"]],
|
|
|
|
null]
|