3 ["load", ["`", "miniMAL-core.json"]],
4 ["load", ["`", "types.json"]],
5 ["load", ["`", "reader.json"]],
6 ["load", ["`", "printer.json"]],
7 ["load", ["`", "env.json"]],
8 ["load", ["`", "core.json"]],
10 ["def", "READ", ["fn", ["strng"], ["read-str", "strng"]]],
12 ["def", "eval-ast", ["fn", ["ast", "env"],
13 ["if", ["symbol?", "ast"],
14 ["env-get", "env", "ast"],
15 ["if", ["list?", "ast"],
16 ["map", ["fn", ["x"], ["EVAL", "x", "env"]], "ast"],
17 ["if", ["vector?", "ast"],
18 ["vectorl", ["map", ["fn", ["x"], ["EVAL", "x", "env"]], "ast"]],
19 ["if", ["map?", "ast"],
20 ["let", ["new-hm", ["hash-map"]],
22 ["map", ["fn", ["k"], ["set", "new-hm",
24 ["EVAL", ["get", "ast", "k"], "env"]]],
29 ["def", "LET", ["fn", ["env", "args"],
30 ["if", [">", ["count", "args"], 0],
32 ["env-set", "env", ["nth", "args", 0],
33 ["EVAL", ["nth", "args", 1], "env"]],
34 ["LET", "env", ["rest", ["rest", "args"]]]]]]],
36 ["def", "EVAL", ["fn", ["ast", "env"],
37 ["if", ["not", ["list?", "ast"]],
38 ["eval-ast", "ast", "env"],
39 ["if", ["empty?", "ast"],
41 ["let", ["a0", ["get", ["first", "ast"], ["`", "val"]]],
42 ["if", ["=", ["`", "def!"], "a0"],
43 ["env-set", "env", ["nth", "ast", 1],
44 ["EVAL", ["nth", "ast", 2], "env"]],
45 ["if", ["=", ["`", "let*"], "a0"],
46 ["let", ["let-env", ["env-new", "env"]],
48 ["LET", "let-env", ["nth", "ast", 1]],
49 ["EVAL", ["nth", "ast", 2], "let-env"]]],
50 ["if", ["=", ["`", "do"], "a0"],
52 ["eval-ast", ["slice", "ast", 1, ["-", ["count", "ast"], 1]], "env"],
53 ["EVAL", ["nth", "ast", ["-", ["count", "ast"], 1]], "env"]],
54 ["if", ["=", ["`", "if"], "a0"],
55 ["let", ["cond", ["EVAL", ["nth", "ast", 1], "env"]],
56 ["if", ["or", ["=", "cond", null], ["=", "cond", false]],
57 ["if", [">", ["count", "ast"], 3],
58 ["EVAL", ["nth", "ast", 3], "env"],
60 ["EVAL", ["nth", "ast", 2], "env"]]],
61 ["if", ["=", ["`", "fn*"], "a0"],
64 ["let", ["e", ["env-new", "env", ["nth", "ast", 1], "args"]],
65 ["EVAL", ["nth", "ast", 2], "e"]]],
66 ["nth", "ast", 2], "env", ["nth", "ast", 1]],
67 ["let", ["el", ["eval-ast", "ast", "env"],
69 "args", ["rest", "el"]],
70 ["if", ["malfunc?", "f"],
71 ["EVAL", ["get", "f", ["`", "ast"]],
72 ["env-new", ["get", "f", ["`", "env"]],
73 ["get", "f", ["`", "params"]],
75 ["apply", "f", "args"]]]]]]]]]]]]],
77 ["def", "PRINT", ["fn", ["exp"],
78 ["pr-str", "exp", true]]],
81 ["def", "repl-env", ["env-new"]],
83 ["def", "rep", ["fn", ["strng"],
85 ["PRINT", ["EVAL", ["READ", "strng"], "repl-env"]],
87 ["str", ["`", "Error: "],
88 ["if", ["isa", "exc", "Error"],
89 [".", "exc", ["`", "toString"]],
90 ["pr-str", "exc", true]]]]]]],
92 ["`", "core.mal: defined using miniMAL"],
93 ["map", ["fn", ["k"], ["env-set", "repl-env",
95 ["get", "core-ns", "k"]]],
97 ["env-set", "repl-env", ["symbol", ["`", "eval"]],
98 ["fn", ["ast"], ["EVAL", "ast", "repl-env"]]],
99 ["env-set", "repl-env", ["symbol", ["`", "*ARGV*"]],
100 ["slice", "ARGS", 1]],
102 ["`", "core.mal: defined using mal itself"],
103 ["rep", ["`", "(def! not (fn* (a) (if a false true)))"]],
104 ["rep", ["`", "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \"\nnil)\")))))"]],
106 ["if", ["not", ["empty?", "ARGS"]],
107 ["rep", ["str", ["`", "(load-file \""], ["get", "ARGS", 0], ["`", "\")"]]],
108 ["repl", ["`", "user> "], "rep"]],