Travis: comment out self-host tests in master.
[jackhill/mal.git] / miniMAL / step7_quote.json
1 ["do",
2
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"]],
9
10 ["def", "READ", ["fn", ["strng"], ["read-str", "strng"]]],
11
12 ["def", "pair?", ["fn", ["x"],
13 ["if", ["sequential?", "x"],
14 ["if", [">", ["count", "x"], 0], true, false],
15 false]]],
16
17 ["def", "quasiquote", ["fn", ["ast"],
18 ["if", ["not", ["pair?", "ast"]],
19 ["list", ["symbol", ["`", "quote"]], "ast"],
20 ["if", ["=", ["`", "unquote"], ["get", ["nth", "ast", 0], ["`", "val"]]],
21 ["nth", "ast", 1],
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"]]]]]]]],
31
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"]],
41 ["do",
42 ["map", ["fn", ["k"], ["set", "new-hm",
43 ["EVAL", "k", "env"],
44 ["EVAL", ["get", "ast", "k"], "env"]]],
45 ["keys", "ast"]],
46 "new-hm"]],
47 "ast"]]]]]],
48
49 ["def", "LET", ["fn", ["env", "args"],
50 ["if", [">", ["count", "args"], 0],
51 ["do",
52 ["env-set", "env", ["nth", "args", 0],
53 ["EVAL", ["nth", "args", 1], "env"]],
54 ["LET", "env", ["rest", ["rest", "args"]]]]]]],
55
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"]],
65 ["do",
66 ["LET", "let-env", ["nth", "ast", 1]],
67 ["EVAL", ["nth", "ast", 2], "let-env"]]],
68 ["if", ["=", ["`", "quote"], "a0"],
69 ["nth", "ast", 1],
70 ["if", ["=", ["`", "quasiquote"], "a0"],
71 ["EVAL", ["quasiquote", ["nth", "ast", 1]], "env"],
72 ["if", ["=", ["`", "do"], "a0"],
73 ["do",
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"],
81 null],
82 ["EVAL", ["nth", "ast", 2], "env"]]],
83 ["if", ["=", ["`", "fn*"], "a0"],
84 ["malfunc",
85 ["fn", ["&", "args"],
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"],
90 "f", ["first", "el"],
91 "args", ["rest", "el"]],
92 ["if", ["malfunc?", "f"],
93 ["EVAL", ["get", "f", ["`", "ast"]],
94 ["env-new", ["get", "f", ["`", "env"]],
95 ["get", "f", ["`", "params"]],
96 "args"]],
97 ["apply", "f", "args"]]]]]]]]]]]]]],
98
99 ["def", "PRINT", ["fn", ["exp"],
100 ["pr-str", "exp", true]]],
101
102
103 ["def", "repl-env", ["env-new"]],
104
105 ["def", "rep", ["fn", ["strng"],
106 ["try",
107 ["PRINT", ["EVAL", ["READ", "strng"], "repl-env"]],
108 ["catch", "exc",
109 ["str", ["`", "Error: "], [".", "exc", ["`", "toString"]]]]]]],
110
111 ["`", "core.mal: defined using miniMAL"],
112 ["map", ["fn", ["k"], ["env-set", "repl-env",
113 ["symbol", "k"],
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]],
120
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) \")\")))))"]],
124
125 ["if", ["not", ["empty?", "*ARGV*"]],
126 ["rep", ["str", ["`", "(load-file \""], ["get", "*ARGV*", 0], ["`", "\")"]]],
127 ["repl", ["`", "user> "], "rep"]],
128
129 null
130
131 ]