aboutsummaryrefslogtreecommitdiff
path: root/miniMAL/miniMAL-core.json
blob: c22376a86b67320037e0b9a420da14b49600be26 (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
["do",

["def", "map", ["fn", ["a", "b"], [".", "b", ["`", "map"], "a"]]],
["def", "not", ["fn", ["a"], ["if", "a", false, true]]],

["def", "nil?", ["fn", ["a"], ["=", null, "a"]]],
["def", "true?", ["fn", ["a"], ["=", true, "a"]]],
["def", "false?", ["fn", ["a"], ["=", false, "a"]]],
["def", "string?", ["fn", ["a"],
  ["if", ["=", "a", null],
    false,
    ["=", ["`", "String"],
          [".-", [".-", "a", ["`", "constructor"]],
                 ["`", "name"]]]]]],

["def", "pr-list*", ["fn", ["a", "pr", "sep"],
  [".", ["map", ["fn", ["x"],
                  ["if", "pr",
                    [".", "JSON", ["`", "stringify"], "x"],
                    ["if", ["string?", "x"],
                      "x",
                      [".", "JSON", ["`", "stringify"], "x"]]]],
              "a"],
      ["`", "join"], "sep"]]],
["def", "pr-str", ["fn", ["&", "a"],
  ["pr-list*", "a", true, ["`", " "]]]],
["def", "str", ["fn", ["&", "a"],
  ["pr-list*", "a", false, ["`", ""]]]],
["def", "prn", ["fn", ["&", "a"],
  [".", "console", ["`", "log"],
    ["pr-list*", "a", true, ["`", " "]]]]],
["def", "println", ["fn", ["&", "a"],
  [".", "console", ["`", "log"],
    ["pr-list*", "a", false, ["`", " "]]]]],

["def", ">=", ["fn", ["a", "b"],
  ["if", ["<", "a", "b"], false, true]]],
["def", ">", ["fn", ["a", "b"],
  ["if", [">=", "a", "b"], ["if", ["=", "a", "b"], false, true], false]]],
["def", "<=", ["fn", ["a", "b"],
  ["if", [">", "a", "b"], false, true]]],

["def", "list", ["fn", ["&", "a"], "a"]],
["def", "list?", ["fn", ["a"], [".", "Array", ["`", "isArray"], "a"]]],
["def", "get", ["fn", ["a", "b"], [".-", "a", "b"]]],
["def", "set", ["fn", ["a", "b", "c"], [".-", "a", "b", "c"]]],
["def", "contains?", ["fn", ["a", "b"], [".", "a", ["`", "hasOwnProperty"], "b"]]],
["def", "keys", ["fn", ["a"], [".", "Object", ["`", "keys"], "a"]]],
["def", "vals", ["fn", ["a"], ["map",["fn",["k"],["get","a","k"]],["keys", "a"]]]],

["def", "cons", ["fn", ["a", "b"],
  [".", ["`", []],
        ["`", "concat"], ["list", "a"], "b"]]],
["def", "concat", ["fn", ["&", "a"],
  [".", [".-", ["list"], ["`", "concat"]],
        ["`", "apply"], ["list"], "a"]]],
["def", "nth", "get"],
["def", "first", ["fn", ["a"], ["nth", "a", 0]]],
["def", "rest", ["fn", ["a"], [".", "a", ["`", "slice"], 1]]],
["def", "empty?", ["fn", ["a"], ["if", ["list?", "a"], ["if", ["=", 0, [".-", "a", ["`", "length"]]], true, false], ["=", "a", null]]]],
["def", "count", ["fn", ["a"],
  [".-", "a", ["`", "length"]]]],
["def", "slice", ["fn", ["a", "start", "&", "endl"],
  ["let", ["end", ["if", ["count", "endl"],
                    ["get", "endl", 0],
                    [".-", "a", ["`", "length"]]]],
    [".", "a", ["`", "slice"], "start", "end"]]]],

["def", "apply", ["fn", ["a", "b"], [".", "a", ["`", "apply"], "a", "b"]]],

["def", "and", ["~", ["fn", ["&", "xs"],
  ["if", ["empty?", "xs"],
    true,
    ["if", ["=", 1, ["count", "xs"]],
      ["first", "xs"],
      ["list", ["`", "let"], ["list", ["`", "and_FIXME"], ["first", "xs"]],
        ["list", ["`", "if"], ["`", "and_FIXME"],
          ["concat", ["`", ["and"]], ["rest", "xs"]],
          ["`", "and_FIXME"]]]]]]]],

["def", "or", ["~", ["fn", ["&", "xs"],
  ["if", ["empty?", "xs"],
    null,
    ["if", ["=", 1, ["count", "xs"]],
      ["first", "xs"],
      ["list", ["`", "let"], ["list", ["`", "or_FIXME"], ["first", "xs"]],
        ["list", ["`", "if"], ["`", "or_FIXME"],
          ["`", "or_FIXME"],
          ["concat", ["`", ["or"]], ["rest", "xs"]]]]]]]]],

["def", "classOf", ["fn", ["a"],
  [".", [".-", [".-", "Object", ["`", "prototype"]], ["`", "toString"]],
        ["`", "call"], "a"]]],


["def", "repl", ["fn",["prompt", "rep"],
  ["let", ["r", ["require", ["`", "repl"]],
           "evl", ["fn", ["l", "c", "f", "cb"],
                    ["let", ["line", ["slice", "l", 1, ["-", [".-", "l", ["`", "length"]], 2]]],
                      ["do",
                        ["println", ["rep", "line"]],
                        ["cb"]]]],
           "opts", {"ignoreUndefined": true,
                    "terminal": false},
           "opts", ["assoc!", "opts", ["`", "prompt"], "prompt"],
           "opts", ["assoc!", "opts", ["`", "eval"], "evl"]],
    [".", "r", ["`", "start"], "opts"]]]],

null
]