1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 18:18:51 +03:00
mal/miniMAL/printer.json
2015-02-25 23:01:16 -06:00

67 lines
2.3 KiB
JSON

["do",
["def", "pr-str", ["fn", ["exp", "print_readably"],
["if", ["list?", "exp"],
["str",
["`", "("],
[".", ["map", ["fn", ["x"], ["pr-str", "x", "print_readably"]], "exp"],
["`", "join"], ["`", " "]],
["`", ")"]],
["if", ["vector?", "exp"],
["str",
["`", "["],
[".", ["map", ["fn", ["x"], ["pr-str", "x", "print_readably"]], "exp"],
["`", "join"], ["`", " "]],
["`", "]"]],
["if", ["map?", "exp"],
["str",
["`", "{"],
[".", ["map", ["fn", ["k"],
["str", ["pr-str", "k", "print_readably"],
["`", " "],
["pr-str", ["get", "exp", "k"], "print_readably"]]],
["keys", "exp"]],
["`", "join"], ["`", " "]],
["`", "}"]],
["if", ["=", ["`", "[object String]"], ["classOf", "exp"]],
["if", ["=", ["`", "\u029e"], ["get", "exp", 0]],
["str", ["`", ":"], ["slice", "exp", 1]],
["if", "print_readably",
["str", ["`", "\""],
[".",
[".",
[".", "exp",
["`", "replace"], ["RegExp", ["`", "\\\\"], ["`", "g"]], ["`", "\\\\"]],
["`", "replace"], ["RegExp", ["`", "\""], ["`", "g"]], ["`", "\\\""]],
["`", "replace"], ["RegExp", ["`", "\n"], ["`", "g"]], ["`", "\\n"]],
["`", "\""]],
"exp"]],
["if", ["=", ["`", "[object Number]"], ["classOf", "exp"]],
"exp",
["if", ["=", null, "exp"],
["`", "nil"],
["if", ["=", true, "exp"],
["`", "true"],
["if", ["=", false, "exp"],
["`", "false"],
["if", ["symbol?", "exp"],
["get", "exp", ["`", "val"]],
["if", ["malfunc?", "exp"],
["str", ["`", "(fn* "],
["pr-str", ["get", "exp", ["`", "params"]]],
["`", " "],
["pr-str", ["get", "exp", ["`", "ast"]]],
["`", ")"]],
["if", ["=", ["`", "[object Function]"], ["classOf", "exp"]],
["str", ["`", "#<native function>"]],
["if", ["atom?", "exp"],
["str", ["`", "(atom "], ["get", "exp", ["`", "val"]], ["`", ")"]],
["str", ["`", "#<unknown: "], "exp", ["`", ">"]]]]]]]]]]]]]]]],
["def", "pr-list", ["fn", ["lst", "print_readably", "sep"],
[".", ["map", ["fn", ["s"], ["pr-str", "s", "print_readably"]], "lst"],
["`", "join"], "sep"]]],
null
]