Change quasiquote algorithm
[jackhill/mal.git] / impls / miniMAL / core.json
CommitLineData
c5d30235
JM
1["do",
2
2774a151
JM
3["def", "_path", ["require", ["`", "path"]]],
4
5["def", "_node_readline", ["require", [".", "_path", ["`", "resolve"],
6 ["`", "."],
7 ["`", "node_readline.js"]]]],
8
6791e640
JM
9["def", "_string?", ["fn", ["s"],
10 ["and", ["string?", "s"],
11 ["not", ["=", ["`", "\u029e"], ["get", "s", 0]]]]]],
12
c5d30235
JM
13["def", "div", ["fn", ["a", "b"], ["parseInt", ["/", "a", "b"]]]],
14
d90c7844
JM
15["def", "time-ms", ["fn", [],
16 [".", ["new", "Date"], ["`", "getTime"]]]],
17
32045546
JM
18
19["def", "assoc", ["fn", ["src-hm", "&", "kvs"],
20 ["let", ["hm", ["clone", "src-hm"]],
21 ["assocs!", "hm", "kvs"]]]],
22
23["def", "dissoc", ["fn", ["src-hm", "&", "ks"],
24 ["let", ["hm", ["clone", "src-hm"]],
25 ["do",
26 ["map", ["fn", ["k"], ["del", "hm", "k"]], "ks"],
27 "hm"]]]],
28
29["def", "_get", ["fn", ["obj", "key"],
b32495e9 30 ["if", ["null?", "obj"],
32045546
JM
31 null,
32 ["if", ["contains?", "obj", "key"],
33 ["get", "obj", "key"],
34 null]]]],
35
c5d30235
JM
36["def", "_count", ["fn", ["a"],
37 ["if", ["=", null, "a"],
38 0,
39 ["count", "a"]]]],
40
f618f6a1
JM
41["def", "_nth", ["fn", ["seq", "idx"],
42 ["if", [">=", "idx", ["count", "seq"]],
43 ["throw", "nth: index out of range"],
44 ["nth", "seq", "idx"]]]],
45
46["def", "_first", ["fn", ["seq"],
47 ["if", ["empty?", "seq"],
48 null,
49 ["first", "seq"]]]],
50
75048743
DM
51["def", "_rest", ["fn", ["seq"],
52 ["if", ["empty?", "seq"],
53 ["`", []],
54 ["rest", "seq"]]]],
55
2774a151
JM
56["def", "_apply", ["fn", ["f", "&", "args"],
57 ["let", ["fn", ["if", ["malfunc?", "f"], ["get", "f", ["`", "fn"]], "f"],
58 "fargs", ["concat", ["slice", "args", 0, ["-", ["count", "args"], 1]],
59 ["nth", "args", ["-", ["count", "args"], 1]]]],
60 ["apply", "fn", "fargs"]]]],
61
62["def", "_map", ["fn", ["f", "seq"],
63 ["let", ["fn", ["if", ["malfunc?", "f"], ["get", "f", ["`", "fn"]], "f"]],
64 ["map", "fn", "seq"]]]],
65
6791e640
JM
66["def", "_conj", ["fn", ["seq", "&", "a"],
67 ["if", ["list?", "seq"],
68 [".", [".", "a", ["`", "reverse"]], ["`", "concat"], "seq"],
69 ["vectorl", [".", "seq", ["`", "concat"], "a"]]]]],
70
71["def", "_seq", ["fn", ["obj"],
72 ["if", ["list?", "obj"],
73 ["if", [">", ["count", "obj"], 0], "obj", null],
74 ["if", ["vector?", "obj"],
75 ["if", [">", ["count", "obj"], 0], ["slice", "obj", 0], null],
76 ["if", ["string?", "obj"],
77 ["if", [">", ["count", "obj"], 0],
78 [".", "obj", ["`", "split"], ["`", ""]],
79 null],
b32495e9 80 ["if", ["null?", "obj"],
6791e640
JM
81 null,
82 ["throw", "seq: called on non-sequence"]
83 ]]]]]],
84
ad28cf3c
JM
85["def", "with_meta", ["fn", ["obj", "m"],
86 ["let", ["new-obj", ["clone", "obj"]],
87 ["do",
88 ["set", "new-obj", ["`", "__meta__"], "m"],
89 "new-obj"]]]],
90
91["def", "meta", ["fn", ["obj"],
92 ["if", ["or", ["sequential?", "obj"],
93 ["map?", "obj"],
94 ["malfunc?", "obj"]],
95 ["if", ["contains?", "obj", ["`", "__meta__"]],
96 ["get", "obj", ["`", "__meta__"]],
97 null],
98 null]]],
99
8cfab776 100["def", "reset!", ["fn", ["atm", "val"],
b32495e9 101 ["do", ["set", "atm", ["`", "val"], "val"], "val"]]],
8cfab776
JM
102
103["def", "swap!", ["fn", ["atm", "f", "&", "args"],
104 ["let", ["fn", ["if", ["malfunc?", "f"], ["get", "f", ["`", "fn"]], "f"],
105 "fargs", ["cons", ["get", "atm", ["`", "val"]], "args"],
106 "val", ["apply", "fn", "fargs"]],
107 ["do",
108 ["set", "atm", ["`", "val"], "val"],
109 "val"]]]],
ad28cf3c 110
c5d30235
JM
111["def", "core-ns",
112 ["hash-map",
2774a151
JM
113 ["`", "="], "equal?",
114 ["`", "throw"], "throw",
115
b32495e9 116 ["`", "nil?"], "null?",
2774a151
JM
117 ["`", "true?"], "true?",
118 ["`", "false?"], "false?",
6791e640 119 ["`", "string?"], "_string?",
2774a151
JM
120 ["`", "symbol"], "symbol",
121 ["`", "symbol?"], "symbol?",
32045546
JM
122 ["`", "keyword"], "keyword",
123 ["`", "keyword?"], "keyword?",
b156d1f1
JM
124 ["`", "number?"], "number?",
125 ["`", "fn?"], ["fn", ["a"],
126 ["or", ["function?", "a"],
127 ["and", ["malfunc?", "a"],
128 ["not", ["get", "a", ["`", "macro?"]]]]]],
129 ["`", "macro?"], ["fn", ["a"],
130 ["and", ["malfunc?", "a"],
131 ["get", "a", ["`", "macro?"]]]],
c5d30235
JM
132
133 ["`", "pr-str"], ["fn", ["&", "a"], ["pr-list", "a", true, ["`", " "]]],
134 ["`", "str"], ["fn", ["&", "a"], ["pr-list", "a", false, ["`", ""]]],
135 ["`", "prn"], ["fn", ["&", "a"],
136 ["do",
137 ["println", ["pr-list", "a", true, ["`", " "]]],
138 null]],
139 ["`", "println"], ["fn", ["&", "a"],
140 ["do",
141 ["println", ["pr-list", "a", false, ["`", " "]]],
142 null]],
9d8f0299 143 ["`", "read-string"], "read-str",
2774a151
JM
144 ["`", "readline"], ["fn", ["p"],
145 [".", "_node_readline", ["`", "readline"], "p"]],
9d8f0299 146 ["`", "slurp"], "slurp",
c5d30235
JM
147
148 ["`", "<"], "<",
149 ["`", "<="], "<=",
150 ["`", ">"], ">",
151 ["`", ">="], ">=",
152 ["`", "+"], "+",
153 ["`", "-"], "-",
154 ["`", "*"], "*",
155 ["`", "/"], "div",
d90c7844 156 ["`", "time-ms"], "time-ms",
c5d30235 157
32045546
JM
158 ["`", "list"], "list",
159 ["`", "list?"], "list?",
160 ["`", "vector"], "vector",
161 ["`", "vector?"], "vector?",
162 ["`", "hash-map"], "hash-map",
163 ["`", "assoc"], "assoc",
164 ["`", "dissoc"], "dissoc",
165 ["`", "map?"], "map?",
166 ["`", "get"], "_get",
167 ["`", "contains?"], "contains?",
168 ["`", "keys"], "keys",
169 ["`", "vals"], "vals",
170
171 ["`", "sequential?"], "sequential?",
1981bf57
JM
172 ["`", "cons"], "cons",
173 ["`", "concat"], "concat",
fbfe6784 174 ["`", "vec"], "vectorl",
f618f6a1
JM
175 ["`", "nth"], "_nth",
176 ["`", "first"], "_first",
75048743 177 ["`", "rest"], "_rest",
c5d30235 178 ["`", "empty?"], "empty?",
8cfab776
JM
179 ["`", "count"], "_count",
180 ["`", "apply"], "_apply",
181 ["`", "map"], "_map",
6791e640
JM
182
183 ["`", "conj"], "_conj",
184 ["`", "seq"], "_seq",
ad28cf3c
JM
185
186 ["`", "with-meta"], "with_meta",
8cfab776
JM
187 ["`", "meta"], "meta",
188 ["`", "atom"], "atom",
189 ["`", "atom?"], "atom?",
190 ["`", "deref"], ["fn", ["a"], ["get", "a", ["`", "val"]]],
191 ["`", "reset!"], "reset!",
192 ["`", "swap!"], "swap!"]],
c5d30235
JM
193
194null]