3 ["load-file", ["`", "miniMAL-core.json"]],
4 ["load-file", ["`", "types.json"]],
5 ["load-file", ["`", "reader.json"]],
6 ["load-file", ["`", "printer.json"]],
7 ["load-file", ["`", "env.json"]],
8 ["load-file", ["`", "core.json"]],
10 ["def", "READ", ["fn", ["strng"], ["read-str", "strng"]]],
12 ["def", "pair?", ["fn", ["x"],
13 ["if", ["sequential?", "x"],
14 ["if", [">", ["count", "x"], 0], true, false],
17 ["def", "quasiquote", ["fn", ["ast"],
18 ["if", ["not", ["pair?", "ast"]],
19 ["list", ["symbol", ["`", "quote"]], "ast"],
20 ["if", ["=", ["`", "unquote"], ["get", ["nth", "ast", 0], ["`", "val"]]],
22 ["if", ["and", ["pair?", ["nth", "ast", 0]],
23 ["=", ["`", "splice-unquote"],
24 ["get", ["nth", ["nth", "ast", 0], 0], ["`", "val"]]]],
25 ["list", ["symbol", ["`", "concat"]],
26 ["nth", ["nth", "ast", 0], 1],
27 ["quasiquote", ["rest", "ast"]]],
28 ["list", ["symbol", ["`", "cons"]],
29 ["quasiquote", ["nth", "ast", 0]],
30 ["quasiquote", ["rest", "ast"]]]]]]]],
32 ["def", "eval-ast", ["fn", ["ast", "env"],
33 ["if", ["symbol?", "ast"],
34 ["env-get", "env", "ast"],
35 ["if", ["list?", "ast"],
36 ["map", ["fn", ["x"], ["EVAL", "x", "env"]], "ast"],
37 ["if", ["vector?", "ast"],
38 ["vectorl", ["map", ["fn", ["x"], ["EVAL", "x", "env"]], "ast"]],
39 ["if", ["map?", "ast"],
40 ["let", ["new-hm", ["hash-map"]],
42 ["map", ["fn", ["k"], ["set", "new-hm",
44 ["EVAL", ["get", "ast", "k"], "env"]]],
49 ["def", "LET", ["fn", ["env", "args"],
50 ["if", [">", ["count", "args"], 0],
52 ["env-set", "env", ["nth", "args", 0],
53 ["EVAL", ["nth", "args", 1], "env"]],
54 ["LET", "env", ["rest", ["rest", "args"]]]]]]],
56 ["def", "EVAL", ["fn", ["ast", "env"],
57 ["if", ["not", ["list?", "ast"]],
58 ["eval-ast", "ast", "env"],
59 ["let", ["a0", ["get", ["first", "ast"], ["`", "val"]]],
60 ["if", ["=", ["`", "def!"], "a0"],
61 ["env-set", "env", ["nth", "ast", 1],
62 ["EVAL", ["nth", "ast", 2], "env"]],
63 ["if", ["=", ["`", "let*"], "a0"],
64 ["let", ["let-env", ["env-new", "env"]],
66 ["LET", "let-env", ["nth", "ast", 1]],
67 ["EVAL", ["nth", "ast", 2], "let-env"]]],
68 ["if", ["=", ["`", "quote"], "a0"],
70 ["if", ["=", ["`", "quasiquote"], "a0"],
71 ["EVAL", ["quasiquote", ["nth", "ast", 1]], "env"],
72 ["if", ["=", ["`", "do"], "a0"],
74 ["eval-ast", ["slice", "ast", 1, ["-", ["count", "ast"], 1]], "env"],
75 ["EVAL", ["nth", "ast", ["-", ["count", "ast"], 1]], "env"]],
76 ["if", ["=", ["`", "if"], "a0"],
77 ["let", ["cond", ["EVAL", ["nth", "ast", 1], "env"]],
78 ["if", ["or", ["=", "cond", null], ["=", "cond", false]],
79 ["if", [">", ["count", "ast"], 3],
80 ["EVAL", ["nth", "ast", 3], "env"],
82 ["EVAL", ["nth", "ast", 2], "env"]]],
83 ["if", ["=", ["`", "fn*"], "a0"],
86 ["let", ["e", ["env-new", "env", ["nth", "ast", 1], "args"]],
87 ["EVAL", ["nth", "ast", 2], "e"]]],
88 ["nth", "ast", 2], "env", ["nth", "ast", 1]],
89 ["let", ["el", ["eval-ast", "ast", "env"],
91 "args", ["rest", "el"]],
92 ["if", ["malfunc?", "f"],
93 ["EVAL", ["get", "f", ["`", "ast"]],
94 ["env-new", ["get", "f", ["`", "env"]],
95 ["get", "f", ["`", "params"]],
97 ["apply", "f", "args"]]]]]]]]]]]]]],
99 ["def", "PRINT", ["fn", ["exp"],
100 ["pr-str", "exp", true]]],
103 ["def", "repl-env", ["env-new"]],
105 ["def", "rep", ["fn", ["strng"],
107 ["PRINT", ["EVAL", ["READ", "strng"], "repl-env"]],
109 ["str", ["`", "Error: "], [".", "exc", ["`", "toString"]]]]]]],
111 ["`", "core.mal: defined using miniMAL"],
112 ["map", ["fn", ["k"], ["env-set", "repl-env",
114 ["get", "core-ns", "k"]]],
115 ["keys", "core-ns"]],
116 ["env-set", "repl-env", ["symbol", ["`", "eval"]],
117 ["fn", ["ast"], ["EVAL", "ast", "repl-env"]]],
118 ["env-set", "repl-env", ["symbol", ["`", "*ARGV*"]],
119 ["slice", "*ARGV*", 1]],
121 ["`", "core.mal: defined using mal itself"],
122 ["rep", ["`", "(def! not (fn* (a) (if a false true)))"]],
123 ["rep", ["`", "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"]],
125 ["if", ["not", ["empty?", "*ARGV*"]],
126 ["rep", ["str", ["`", "(load-file \""], ["get", "*ARGV*", 0], ["`", "\")"]]],
127 ["repl", ["`", "user> "], "rep"]],