Change quasiquote algorithm
[jackhill/mal.git] / impls / miniMAL / step3_env.json
1 ["do",
2
3 ["load", ["`", "miniMAL-core.json"]],
4 ["load", ["`", "types.json"]],
5 ["load", ["`", "reader.json"]],
6 ["load", ["`", "printer.json"]],
7 ["load", ["`", "env.json"]],
8
9 ["def", "READ", ["fn", ["strng"],
10 ["read-str", "strng"]]],
11
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"]],
21 ["do",
22 ["map", ["fn", ["k"], ["set", "new-hm",
23 ["EVAL", "k", "env"],
24 ["EVAL", ["get", "ast", "k"], "env"]]],
25 ["keys", "ast"]],
26 "new-hm"]],
27 "ast"]]]]]],
28
29 ["def", "LET", ["fn", ["env", "args"],
30 ["if", [">", ["count", "args"], 0],
31 ["do",
32 ["env-set", "env", ["nth", "args", 0],
33 ["EVAL", ["nth", "args", 1], "env"]],
34 ["LET", "env", ["rest", ["rest", "args"]]]]]]],
35
36 ["def", "EVAL", ["fn", ["ast", "env"],
37 ["if", ["not", ["list?", "ast"]],
38 ["eval-ast", "ast", "env"],
39 ["if", ["empty?", "ast"],
40 "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"]],
47 ["do",
48 ["LET", "let-env", ["nth", "ast", 1]],
49 ["EVAL", ["nth", "ast", 2], "let-env"]]],
50 ["let", ["el", ["eval-ast", "ast", "env"],
51 "f", ["first", "el"],
52 "args", ["rest", "el"]],
53 ["apply", "f", "args"]]]]]]]]],
54
55 ["def", "PRINT", ["fn", ["exp"],
56 ["pr-str", "exp", true]]],
57
58
59 ["def", "repl-env", ["env-new"]],
60 ["env-set", "repl-env", ["symbol", ["`", "+"]], "+"],
61 ["env-set", "repl-env", ["symbol", ["`", "-"]], "-"],
62 ["env-set", "repl-env", ["symbol", ["`", "*"]], "*"],
63 ["def", "div", ["fn", ["a", "b"], ["parseInt", ["/", "a", "b"]]]],
64 ["env-set", "repl-env", ["symbol", ["`", "/"]], "div"],
65
66 ["def", "rep", ["fn", ["strng"],
67 ["try",
68 ["PRINT", ["EVAL", ["READ", "strng"], "repl-env"]],
69 ["catch", "exc",
70 ["str", ["`", "Error: "], [".", "exc", ["`", "toString"]]]]]]],
71
72 ["repl", ["`", "user> "], "rep"],
73
74 null
75
76 ]