aboutsummaryrefslogtreecommitdiff
path: root/miniMAL/core.json
blob: 164a846aa86b3889378f0316100afa21115fb5d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
["do",

["def", "_path", ["require", ["`", "path"]]],

["def", "_node_readline", ["require", [".", "_path", ["`", "resolve"],
                                            ["`", "."],
                                            ["`", "node_readline.js"]]]],

["def", "div", ["fn", ["a", "b"], ["parseInt", ["/", "a", "b"]]]],

["def", "time-ms", ["fn", [],
  [".", ["new", "Date"], ["`", "getTime"]]]],


["def", "assoc", ["fn", ["src-hm", "&", "kvs"],
  ["let", ["hm", ["clone", "src-hm"]],
    ["assocs!", "hm", "kvs"]]]],

["def", "dissoc", ["fn", ["src-hm", "&", "ks"],
  ["let", ["hm", ["clone", "src-hm"]],
    ["do",
      ["map", ["fn", ["k"], ["del", "hm", "k"]], "ks"],
      "hm"]]]],

["def", "_get", ["fn", ["obj", "key"],
  ["if", ["nil?", "obj"],
    null,
    ["if", ["contains?", "obj", "key"],
      ["get", "obj", "key"],
      null]]]],

["def", "_count", ["fn", ["a"],
  ["if", ["=", null, "a"],
    0,
    ["count", "a"]]]],

["def", "_nth", ["fn", ["seq", "idx"],
  ["if", [">=", "idx", ["count", "seq"]],
    ["throw", "nth: index out of range"],
    ["nth", "seq", "idx"]]]],

["def", "_first", ["fn", ["seq"],
  ["if", ["empty?", "seq"],
    null,
    ["first", "seq"]]]],

["def", "_apply", ["fn", ["f", "&", "args"],
  ["let", ["fn", ["if", ["malfunc?", "f"], ["get", "f", ["`", "fn"]], "f"],
           "fargs", ["concat", ["slice", "args", 0, ["-", ["count", "args"], 1]],
                               ["nth", "args", ["-", ["count", "args"], 1]]]],
    ["apply", "fn", "fargs"]]]],

["def", "_map", ["fn", ["f", "seq"],
  ["let", ["fn", ["if", ["malfunc?", "f"], ["get", "f", ["`", "fn"]], "f"]],
    ["map", "fn", "seq"]]]],

["def", "with_meta", ["fn", ["obj", "m"],
  ["let", ["new-obj", ["clone", "obj"]],
    ["do",
      ["set", "new-obj", ["`", "__meta__"], "m"],
      "new-obj"]]]],

["def", "meta", ["fn", ["obj"],
  ["if", ["or", ["sequential?", "obj"],
                ["map?", "obj"],
                ["malfunc?", "obj"]],
    ["if", ["contains?", "obj", ["`", "__meta__"]],
      ["get", "obj", ["`", "__meta__"]],
      null],
    null]]],

["def", "reset!", ["fn", ["atm", "val"],
  ["set", "atm", ["`", "val"], "val"]]],

["def", "swap!", ["fn", ["atm", "f", "&", "args"],
  ["let", ["fn", ["if", ["malfunc?", "f"], ["get", "f", ["`", "fn"]], "f"],
           "fargs", ["cons", ["get", "atm", ["`", "val"]], "args"],
           "val", ["apply", "fn", "fargs"]],
  ["do",
    ["set", "atm", ["`", "val"], "val"],
    "val"]]]],

["def", "core-ns",
  ["hash-map",
   ["`", "="], "equal?",
   ["`", "throw"], "throw",

   ["`", "nil?"], "nil?",
   ["`", "true?"], "true?",
   ["`", "false?"], "false?",
   ["`", "symbol"], "symbol",
   ["`", "symbol?"], "symbol?",
   ["`", "keyword"], "keyword",
   ["`", "keyword?"], "keyword?",

   ["`", "pr-str"],  ["fn", ["&", "a"], ["pr-list", "a", true, ["`", " "]]],
   ["`", "str"],     ["fn", ["&", "a"], ["pr-list", "a", false, ["`", ""]]],
   ["`", "prn"],     ["fn", ["&", "a"],
                       ["do",
                         ["println", ["pr-list", "a", true, ["`", " "]]],
                         null]],
   ["`", "println"], ["fn", ["&", "a"],
                       ["do",
                         ["println", ["pr-list", "a", false, ["`", " "]]],
                         null]],
   ["`", "read-string"], "read-str",
   ["`", "readline"], ["fn", ["p"],
                        [".", "_node_readline", ["`", "readline"], "p"]],
   ["`", "slurp"], "slurp",

   ["`", "<"],  "<",
   ["`", "<="], "<=",
   ["`", ">"],  ">",
   ["`", ">="], ">=",
   ["`", "+"],  "+",
   ["`", "-"],  "-",
   ["`", "*"],  "*",
   ["`", "/"],  "div",
   ["`", "time-ms"], "time-ms",

   ["`", "list"], "list",
   ["`", "list?"], "list?",
   ["`", "vector"], "vector",
   ["`", "vector?"], "vector?",
   ["`", "hash-map"], "hash-map",
   ["`", "assoc"], "assoc",
   ["`", "dissoc"], "dissoc",
   ["`", "map?"], "map?",
   ["`", "get"], "_get",
   ["`", "contains?"], "contains?",
   ["`", "keys"], "keys",
   ["`", "vals"], "vals",

   ["`", "sequential?"], "sequential?",
   ["`", "cons"], "cons",
   ["`", "concat"], "concat",
   ["`", "nth"], "_nth",
   ["`", "first"], "_first",
   ["`", "rest"], ["fn", ["a"], ["rest", "a"]],
   ["`", "empty?"], "empty?",
   ["`", "count"], "_count",
   ["`", "apply"], "_apply",
   ["`", "map"], "_map",
   ["`", "conj"], null,

   ["`", "with-meta"], "with_meta",
   ["`", "meta"], "meta",
   ["`", "atom"], "atom",
   ["`", "atom?"], "atom?",
   ["`", "deref"], ["fn", ["a"], ["get", "a", ["`", "val"]]],
   ["`", "reset!"], "reset!",
   ["`", "swap!"], "swap!"]],

null]