@fraczak/k 1.2.3 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/INTRO.md ADDED
@@ -0,0 +1,131 @@
1
+ # k - the way of building and manipulating JSON-like data
2
+
3
+ Technically: notation for defining __first-order partial functions__.
4
+
5
+ An example of a _partial function_ is "`.toto`", which maps an object
6
+ to its property named `toto`, or it is not defined if the property
7
+ doesn't exist. E.g.,
8
+
9
+ .toto :
10
+ {"toto": 5, "titi": 10} --> 5
11
+ {"titi": 10} ... undefined // it is not a value!
12
+
13
+ ---
14
+
15
+ ## Combining "partial functions"
16
+
17
+ There are three ways of combining functions:
18
+
19
+ 1. __composition__: `(f1 f2 ...)`, e.g. `(.toto .titi)` extracts
20
+ nested field.
21
+
22
+ (.toto .titi) :
23
+ {"toto": {"titi": 10}} --> 10
24
+ {"toto": 10 } ... undefined
25
+ {} ... undefined
26
+
27
+ 2. __merge__: `< f1, f2,... >`, e.g., `<.toto, .titi>` extracts field
28
+ `toto` if present; otherwise extracts `titi`.
29
+
30
+ <.toto, .titi> :
31
+ {"toto": 5, "titi": 10} --> 5
32
+ {"titi": 10 } --> 10
33
+ {} ... undefined
34
+
35
+ 3. __product__: `{ f1 label1, f2 label2, ...}`, e.g., `{.toto TOTO,
36
+ .titi TITI}` extracts two fields and builds a record out of them.
37
+
38
+ {.toto TOTO, .titi TITI} :
39
+ {"toto": 5, "titi": 10} --> {"TOTO": 5, "TITI": 10}
40
+ {"titi": 10 } ... undefined
41
+
42
+ ---
43
+
44
+ __QUIZ__: What is:
45
+
46
+ - empty composition: `()` ?
47
+ - empty merge: `<>` ?
48
+ - empty product: `{}` ?
49
+ - `{{{{} s} s} s}` ?
50
+ - `({{{() a} b} c} .c .b .a)` ?
51
+
52
+ ---
53
+
54
+ ## Basic extensions
55
+
56
+ ### Constants, i.e., literals for `strings`, `integers`, `booleans`, and `null`
57
+
58
+ A constant defines a function which ignores its argument and produces
59
+ the constant value. E.g.:
60
+
61
+ {123 int, "kScript" str, true bool, null null} :
62
+ <any> --> {"int":123,"str":"kScript","bool":true,"null":null}
63
+
64
+ ### Vector product
65
+
66
+ Vector product can be used as an abbreviation for product whose field
67
+ names are integers starting from zero. E.g., `{.toto "0", .titi "1",
68
+ 123 "2"}` can be written as `[.toto, .titi, 123]`.
69
+
70
+ [.toto, .titi, 12] :
71
+ {"toto": 5, "titi": 10 } --> [5, 10, 12] // {"0":5,"1":10,"2":12}
72
+
73
+ .1 :
74
+ ["A","B","C"] --> "B"
75
+ ["a"] ... undefined
76
+ ---
77
+
78
+ ## Pragmatic extensions, aka "standard library"
79
+
80
+ - `GT` :
81
+
82
+ [4,3,0] --> [4,3,0]
83
+ [5,8] - undefined
84
+
85
+ - `EQ` :
86
+
87
+ [4,4,4] --> [4,4,4]
88
+ [5,8] - undefined
89
+
90
+ - `[PLUS, TIMES, MINUS]` :
91
+
92
+ [2,2,2] --> [6,8,-2]
93
+
94
+ - `CONCAT` :
95
+
96
+ ["a","bc","d"] --> "abcd"
97
+
98
+ - `toJSON` :
99
+
100
+ {a: 12} --> "{\"a\":12}"
101
+
102
+ - `fromJSON` :
103
+
104
+ "{\"a\":12}" --> {a: 12}
105
+
106
+ - `DIV`, `FDIV`, `CONS`, `SNOC`, `_log!`
107
+
108
+ ---
109
+
110
+ ## Recursive definitions
111
+
112
+ -- factorial.k
113
+ dec = ([(),-1] PLUS);
114
+ zero? = ([(),0] EQ 0);
115
+ factorial = <
116
+ (zero? 1),
117
+ ([(dec factorial), ()] TIMES)
118
+ >;
119
+ { () x, factorial "x!" }
120
+
121
+ ## Codes (_types_)
122
+
123
+ _Codes_ (prefixed by `$`) can be defined by taged union and product. E.g.:
124
+
125
+ $nat = <nat s, {} z>; -- e.g., {{{{} z} s} s}
126
+ $pair = {nat x, nat y}; -- e.g., {{{} z} x, {{{{} z} s} s} y}
127
+
128
+ s = ($nat {() s} $nat);
129
+ add = ($pair <{(.x .s) x, (.y s) y} add, .y> $nat);
130
+
131
+
package/README.md CHANGED
@@ -72,12 +72,13 @@ the field (or a vector with the index).
72
72
 
73
73
  `k`-expression can be prefixed by function definitions. E.g.:
74
74
 
75
- dec = [(),1] MINUS;
76
- factorial = <
77
- [(),1] EQ 1,
78
- [dec factorial, ()] TIMES
79
- >;
80
- { () x, < factorial, "not defined" > "x!" }
75
+ dec = [(),-1] PLUS;
76
+ zero? = [(),0] EQ 0;
77
+ factorial = <
78
+ zero? 1,
79
+ [dec factorial, ()] TIMES
80
+ >;
81
+ { () x, factorial "x!" }
81
82
 
82
83
  Another example could be finding the biggest (max) value in a vector:
83
84
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fraczak/k",
3
- "version": "1.2.3",
3
+ "version": "1.3.0",
4
4
  "description": "k-language for JSON-like data transformation",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/parser.jison CHANGED
@@ -82,8 +82,10 @@ non_empty_labelled_codes
82
82
  code_label
83
83
  : code name { $$ = {label: $2, code: $1}; }
84
84
  | code str { $$ = {label: $2, code: $1}; }
85
+ | code int { $$ = {label: $2, code: $1}; }
85
86
  | name COL code { $$ = {label: $1, code: $3}; }
86
87
  | str COL code { $$ = {label: $1, code: $3}; }
88
+ | int COL code { $$ = {label: $1, code: $3}; }
87
89
  ;
88
90
 
89
91
  comp
@@ -121,8 +123,10 @@ non_empty_labelled
121
123
  comp_label
122
124
  : comp name { $$ = {label: $2, exp: $1}; }
123
125
  | comp str { $$ = {label: $2, exp: $1}; }
126
+ | comp int { $$ = {label: $2, exp: $1}; }
124
127
  | name COL comp { $$ = {label: $1, exp: $3}; }
125
128
  | str COL comp { $$ = {label: $1, exp: $3}; }
129
+ | int COL comp { $$ = {label: $1, exp: $3}; }
126
130
  ;
127
131
 
128
132
  list
package/parser.js CHANGED
@@ -72,12 +72,12 @@
72
72
  }
73
73
  */
74
74
  var parser = (function(){
75
- var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[4,6,8,15,18,21,23,32,34],$V1=[1,7],$V2=[1,15],$V3=[1,16],$V4=[1,8],$V5=[1,9],$V6=[1,10],$V7=[1,11],$V8=[1,14],$V9=[1,20],$Va=[4,6,8,12,15,18,21,23,32,34],$Vb=[2,26],$Vc=[1,25],$Vd=[1,26],$Ve=[1,27],$Vf=[4,6,8,12,14,15,18,20,21,22,23,24,27,32,33,34],$Vg=[2,43],$Vh=[2,29],$Vi=[2,8],$Vj=[2,13],$Vk=[20,27],$Vl=[22,24,27],$Vm=[20,24,27],$Vn=[2,39],$Vo=[2,40];
75
+ var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o},$V0=[4,6,8,15,18,21,23,32,34],$V1=[1,7],$V2=[1,15],$V3=[1,16],$V4=[1,8],$V5=[1,9],$V6=[1,10],$V7=[1,11],$V8=[1,14],$V9=[1,20],$Va=[4,6,8,12,15,18,21,23,32,34],$Vb=[2,28],$Vc=[1,25],$Vd=[1,26],$Ve=[1,27],$Vf=[4,6,8,12,14,15,18,20,21,22,23,24,27,32,33,34],$Vg=[2,47],$Vh=[2,31],$Vi=[2,32],$Vj=[4,6,8,12,14,15,18,20,21,22,23,24,27,28,32,33,34],$Vk=[2,8],$Vl=[2,13],$Vm=[20,27],$Vn=[22,24,27],$Vo=[20,24,27],$Vp=[2,41],$Vq=[2,42],$Vr=[2,43];
76
76
  var parser = {trace: function trace () { },
77
77
  yy: {},
78
78
  symbols_: {"error":2,"name":3,"NAME":4,"str":5,"STRING":6,"int":7,"INT":8,"input_with_eof":9,"defs":10,"comp":11,"EOF":12,"EQ":13,"SC":14,"DOLLAR":15,"codeDef":16,"code":17,"LC":18,"labelled_codes":19,"RC":20,"LB":21,"RB":22,"LA":23,"RA":24,"non_empty_labelled_codes":25,"code_label":26,"COMMA":27,"COL":28,"exp":29,"labelled":30,"list":31,"LP":32,"RP":33,"DOT":34,"non_empty_labelled":35,"comp_label":36,"non_empty_list":37,"$accept":0,"$end":1},
79
79
  terminals_: {2:"error",4:"NAME",6:"STRING",8:"INT",12:"EOF",13:"EQ",14:"SC",15:"DOLLAR",18:"LC",20:"RC",21:"LB",22:"RB",23:"LA",24:"RA",27:"COMMA",28:"COL",32:"LP",33:"RP",34:"DOT"},
80
- productions_: [0,[3,1],[5,1],[7,1],[9,3],[10,0],[10,5],[10,6],[17,1],[17,1],[16,3],[16,3],[16,3],[19,0],[19,1],[25,1],[25,3],[26,2],[26,2],[26,3],[26,3],[11,1],[11,2],[29,3],[29,3],[29,3],[29,1],[29,2],[29,3],[29,1],[29,1],[29,2],[29,2],[29,2],[29,2],[30,0],[30,1],[35,1],[35,3],[36,2],[36,2],[36,3],[36,3],[31,0],[31,1],[37,1],[37,3]],
80
+ productions_: [0,[3,1],[5,1],[7,1],[9,3],[10,0],[10,5],[10,6],[17,1],[17,1],[16,3],[16,3],[16,3],[19,0],[19,1],[25,1],[25,3],[26,2],[26,2],[26,2],[26,3],[26,3],[26,3],[11,1],[11,2],[29,3],[29,3],[29,3],[29,1],[29,2],[29,3],[29,1],[29,1],[29,2],[29,2],[29,2],[29,2],[30,0],[30,1],[35,1],[35,3],[36,2],[36,2],[36,2],[36,3],[36,3],[36,3],[31,0],[31,1],[37,1],[37,3]],
81
81
  performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
82
82
  /* this == yyval */
83
83
 
@@ -111,7 +111,7 @@ break;
111
111
  case 8:
112
112
  this.$ = {code: "ref", ref: $$[$0]};
113
113
  break;
114
- case 9: case 21: case 36: case 44:
114
+ case 9: case 23: case 38: case 48:
115
115
  this.$ = $$[$0];
116
116
  break;
117
117
  case 10:
@@ -132,72 +132,72 @@ case 14:
132
132
  return r }
133
133
  , {});
134
134
  break;
135
- case 15: case 45:
135
+ case 15: case 49:
136
136
  this.$ = [$$[$0]];
137
137
  break;
138
- case 16: case 46:
138
+ case 16: case 50:
139
139
  this.$ = [].concat($$[$0-2],$$[$0]);
140
140
  break;
141
- case 17: case 18:
141
+ case 17: case 18: case 19:
142
142
  this.$ = {label: $$[$0], code: $$[$0-1]};
143
143
  break;
144
- case 19: case 20:
144
+ case 20: case 21: case 22:
145
145
  this.$ = {label: $$[$0-2], code: $$[$0]};
146
146
  break;
147
- case 22:
147
+ case 24:
148
148
  this.$ = s.comp($$[$0-1], $$[$0]);
149
149
  break;
150
- case 23:
150
+ case 25:
151
151
  this.$ = $$[$0-1];
152
152
  break;
153
- case 24:
153
+ case 26:
154
154
  this.$ = {op: "vector", vector: $$[$0-1]};
155
155
  break;
156
- case 25:
156
+ case 27:
157
157
  this.$ = s.union($$[$0-1]);
158
158
  break;
159
- case 26:
159
+ case 28:
160
160
  this.$ = {op: "ref", ref: $$[$0]};
161
161
  break;
162
- case 27:
162
+ case 29:
163
163
  this.$ = s.identity;
164
164
  break;
165
- case 28:
165
+ case 30:
166
166
  this.$ = $$[$0-1];
167
167
  break;
168
- case 29:
168
+ case 31:
169
169
  this.$ = {op: "str", str: $$[$0]};
170
170
  break;
171
- case 30:
171
+ case 32:
172
172
  this.$ = {op: "int", int: $$[$0]};
173
173
  break;
174
- case 31: case 32: case 33:
174
+ case 33: case 34: case 35:
175
175
  this.$ = {op: "dot", dot: $$[$0]};
176
176
  break;
177
- case 34:
177
+ case 36:
178
178
  this.$ = {op: "code", code: s.as_ref($$[$0])};
179
179
  break;
180
- case 35:
180
+ case 37:
181
181
  this.$ = {op: "product", product: []};
182
182
  break;
183
- case 37:
183
+ case 39:
184
184
  this.$ = {op: "product", product: [$$[$0]]};
185
185
  break;
186
- case 38:
186
+ case 40:
187
187
  $$[$0-2].product = [].concat($$[$0-2].product,$$[$0]); this.$ = $$[$0-2];
188
188
  break;
189
- case 39: case 40:
189
+ case 41: case 42: case 43:
190
190
  this.$ = {label: $$[$0], exp: $$[$0-1]};
191
191
  break;
192
- case 41: case 42:
192
+ case 44: case 45: case 46:
193
193
  this.$ = {label: $$[$0-2], exp: $$[$0]};
194
194
  break;
195
- case 43:
195
+ case 47:
196
196
  this.$ = [];
197
197
  break;
198
198
  }
199
199
  },
200
- table: [o($V0,[2,5],{9:1,10:2}),{1:[3]},{3:4,4:$V1,5:12,6:$V2,7:13,8:$V3,11:3,15:[1,5],18:$V4,21:$V5,23:$V6,29:6,32:$V7,34:$V8},{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,12:[1,17],15:$V9,18:$V4,21:$V5,23:$V6,29:18,32:$V7,34:$V8},o($Va,$Vb,{13:[1,21]}),{3:22,4:$V1,16:24,17:23,18:$Vc,21:$Vd,23:$Ve},o($Vf,[2,21]),o([4,6,8,12,13,14,15,18,20,21,22,23,24,27,28,32,33,34],[2,1]),{3:32,4:$V1,5:33,6:$V2,7:13,8:$V3,11:31,15:$V9,18:$V4,20:[2,35],21:$V5,23:$V6,29:6,30:28,32:$V7,34:$V8,35:29,36:30},{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,11:36,15:$V9,18:$V4,21:$V5,22:$Vg,23:$V6,29:6,31:34,32:$V7,34:$V8,37:35},{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,11:36,15:$V9,18:$V4,21:$V5,23:$V6,24:$Vg,29:6,31:37,32:$V7,34:$V8,37:35},{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,11:39,15:$V9,18:$V4,21:$V5,23:$V6,29:6,32:$V7,33:[1,38],34:$V8},o($Vf,$Vh),o($Vf,[2,30]),{3:42,4:$V1,5:41,6:$V2,7:40,8:$V3},o([4,6,8,12,14,15,18,20,21,22,23,24,27,28,32,33,34],[2,2]),o($Vf,[2,3]),{1:[2,4]},o($Vf,[2,22]),o($Vf,$Vb),{3:43,4:$V1,16:24,17:23,18:$Vc,21:$Vd,23:$Ve},{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,11:44,15:$V9,18:$V4,21:$V5,23:$V6,29:6,32:$V7,34:$V8},o($Va,$Vi,{13:[1,45]}),o($Vf,[2,34]),o($Vf,[2,9]),{3:50,4:$V1,5:51,6:$V2,16:24,17:49,18:$Vc,19:46,20:$Vj,21:$Vd,23:$Ve,25:47,26:48},{3:43,4:$V1,16:24,17:52,18:$Vc,21:$Vd,23:$Ve},{3:50,4:$V1,5:51,6:$V2,16:24,17:49,18:$Vc,19:53,21:$Vd,23:$Ve,24:$Vj,25:47,26:48},{20:[1,54]},{20:[2,36],27:[1,55]},o($Vk,[2,37]),{3:56,4:$V1,5:57,6:$V2,7:13,8:$V3,15:$V9,18:$V4,21:$V5,23:$V6,29:18,32:$V7,34:$V8},o($V0,$Vb,{28:[1,58]}),o($V0,$Vh,{28:[1,59]}),{22:[1,60]},o([22,24],[2,44],{27:[1,61]}),o($Vl,[2,45],{5:12,7:13,29:18,3:19,4:$V1,6:$V2,8:$V3,15:$V9,18:$V4,21:$V5,23:$V6,32:$V7,34:$V8}),{24:[1,62]},o($Vf,[2,27]),{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,15:$V9,18:$V4,21:$V5,23:$V6,29:18,32:$V7,33:[1,63],34:$V8},o($Vf,[2,31]),o($Vf,[2,32]),o($Vf,[2,33]),o($Vf,$Vi),{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,14:[1,64],15:$V9,18:$V4,21:$V5,23:$V6,29:18,32:$V7,34:$V8},{16:65,18:$Vc,21:$Vd,23:$Ve},{20:[1,66]},o([20,24],[2,14],{27:[1,67]}),o($Vm,[2,15]),{3:68,4:$V1,5:69,6:$V2},o([4,6],$Vi,{28:[1,70]}),{28:[1,71]},{22:[1,72]},{24:[1,73]},o($Vf,[2,23]),{3:32,4:$V1,5:33,6:$V2,7:13,8:$V3,11:31,15:$V9,18:$V4,21:$V5,23:$V6,29:6,32:$V7,34:$V8,36:74},o($V0,$Vb,{20:$Vn,27:$Vn}),o($V0,$Vh,{20:$Vo,27:$Vo}),{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,11:75,15:$V9,18:$V4,21:$V5,23:$V6,29:6,32:$V7,34:$V8},{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,11:76,15:$V9,18:$V4,21:$V5,23:$V6,29:6,32:$V7,34:$V8},o($Vf,[2,24]),{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,11:77,15:$V9,18:$V4,21:$V5,23:$V6,29:6,32:$V7,34:$V8},o($Vf,[2,25]),o($Vf,[2,28]),o($V0,[2,6]),{14:[1,78]},o($Vf,[2,10]),{3:50,4:$V1,5:51,6:$V2,16:24,17:49,18:$Vc,21:$Vd,23:$Ve,26:79},o($Vm,[2,17]),o($Vm,[2,18]),{3:43,4:$V1,16:24,17:80,18:$Vc,21:$Vd,23:$Ve},{3:43,4:$V1,16:24,17:81,18:$Vc,21:$Vd,23:$Ve},o($Vf,[2,11]),o($Vf,[2,12]),o($Vk,[2,38]),o($Vk,[2,41],{5:12,7:13,29:18,3:19,4:$V1,6:$V2,8:$V3,15:$V9,18:$V4,21:$V5,23:$V6,32:$V7,34:$V8}),o($Vk,[2,42],{5:12,7:13,29:18,3:19,4:$V1,6:$V2,8:$V3,15:$V9,18:$V4,21:$V5,23:$V6,32:$V7,34:$V8}),o($Vl,[2,46],{5:12,7:13,29:18,3:19,4:$V1,6:$V2,8:$V3,15:$V9,18:$V4,21:$V5,23:$V6,32:$V7,34:$V8}),o($V0,[2,7]),o($Vm,[2,16]),o($Vm,[2,19]),o($Vm,[2,20])],
200
+ table: [o($V0,[2,5],{9:1,10:2}),{1:[3]},{3:4,4:$V1,5:12,6:$V2,7:13,8:$V3,11:3,15:[1,5],18:$V4,21:$V5,23:$V6,29:6,32:$V7,34:$V8},{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,12:[1,17],15:$V9,18:$V4,21:$V5,23:$V6,29:18,32:$V7,34:$V8},o($Va,$Vb,{13:[1,21]}),{3:22,4:$V1,16:24,17:23,18:$Vc,21:$Vd,23:$Ve},o($Vf,[2,23]),o([4,6,8,12,13,14,15,18,20,21,22,23,24,27,28,32,33,34],[2,1]),{3:32,4:$V1,5:33,6:$V2,7:34,8:$V3,11:31,15:$V9,18:$V4,20:[2,37],21:$V5,23:$V6,29:6,30:28,32:$V7,34:$V8,35:29,36:30},{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,11:37,15:$V9,18:$V4,21:$V5,22:$Vg,23:$V6,29:6,31:35,32:$V7,34:$V8,37:36},{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,11:37,15:$V9,18:$V4,21:$V5,23:$V6,24:$Vg,29:6,31:38,32:$V7,34:$V8,37:36},{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,11:40,15:$V9,18:$V4,21:$V5,23:$V6,29:6,32:$V7,33:[1,39],34:$V8},o($Vf,$Vh),o($Vf,$Vi),{3:43,4:$V1,5:42,6:$V2,7:41,8:$V3},o($Vj,[2,2]),o($Vj,[2,3]),{1:[2,4]},o($Vf,[2,24]),o($Vf,$Vb),{3:44,4:$V1,16:24,17:23,18:$Vc,21:$Vd,23:$Ve},{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,11:45,15:$V9,18:$V4,21:$V5,23:$V6,29:6,32:$V7,34:$V8},o($Va,$Vk,{13:[1,46]}),o($Vf,[2,36]),o($Vf,[2,9]),{3:51,4:$V1,5:52,6:$V2,7:53,8:$V3,16:24,17:50,18:$Vc,19:47,20:$Vl,21:$Vd,23:$Ve,25:48,26:49},{3:44,4:$V1,16:24,17:54,18:$Vc,21:$Vd,23:$Ve},{3:51,4:$V1,5:52,6:$V2,7:53,8:$V3,16:24,17:50,18:$Vc,19:55,21:$Vd,23:$Ve,24:$Vl,25:48,26:49},{20:[1,56]},{20:[2,38],27:[1,57]},o($Vm,[2,39]),{3:58,4:$V1,5:59,6:$V2,7:60,8:$V3,15:$V9,18:$V4,21:$V5,23:$V6,29:18,32:$V7,34:$V8},o($V0,$Vb,{28:[1,61]}),o($V0,$Vh,{28:[1,62]}),o($V0,$Vi,{28:[1,63]}),{22:[1,64]},o([22,24],[2,48],{27:[1,65]}),o($Vn,[2,49],{5:12,7:13,29:18,3:19,4:$V1,6:$V2,8:$V3,15:$V9,18:$V4,21:$V5,23:$V6,32:$V7,34:$V8}),{24:[1,66]},o($Vf,[2,29]),{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,15:$V9,18:$V4,21:$V5,23:$V6,29:18,32:$V7,33:[1,67],34:$V8},o($Vf,[2,33]),o($Vf,[2,34]),o($Vf,[2,35]),o($Vf,$Vk),{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,14:[1,68],15:$V9,18:$V4,21:$V5,23:$V6,29:18,32:$V7,34:$V8},{16:69,18:$Vc,21:$Vd,23:$Ve},{20:[1,70]},o([20,24],[2,14],{27:[1,71]}),o($Vo,[2,15]),{3:72,4:$V1,5:73,6:$V2,7:74,8:$V3},o([4,6,8],$Vk,{28:[1,75]}),{28:[1,76]},{28:[1,77]},{22:[1,78]},{24:[1,79]},o($Vf,[2,25]),{3:32,4:$V1,5:33,6:$V2,7:34,8:$V3,11:31,15:$V9,18:$V4,21:$V5,23:$V6,29:6,32:$V7,34:$V8,36:80},o($V0,$Vb,{20:$Vp,27:$Vp}),o($V0,$Vh,{20:$Vq,27:$Vq}),o($V0,$Vi,{20:$Vr,27:$Vr}),{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,11:81,15:$V9,18:$V4,21:$V5,23:$V6,29:6,32:$V7,34:$V8},{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,11:82,15:$V9,18:$V4,21:$V5,23:$V6,29:6,32:$V7,34:$V8},{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,11:83,15:$V9,18:$V4,21:$V5,23:$V6,29:6,32:$V7,34:$V8},o($Vf,[2,26]),{3:19,4:$V1,5:12,6:$V2,7:13,8:$V3,11:84,15:$V9,18:$V4,21:$V5,23:$V6,29:6,32:$V7,34:$V8},o($Vf,[2,27]),o($Vf,[2,30]),o($V0,[2,6]),{14:[1,85]},o($Vf,[2,10]),{3:51,4:$V1,5:52,6:$V2,7:53,8:$V3,16:24,17:50,18:$Vc,21:$Vd,23:$Ve,26:86},o($Vo,[2,17]),o($Vo,[2,18]),o($Vo,[2,19]),{3:44,4:$V1,16:24,17:87,18:$Vc,21:$Vd,23:$Ve},{3:44,4:$V1,16:24,17:88,18:$Vc,21:$Vd,23:$Ve},{3:44,4:$V1,16:24,17:89,18:$Vc,21:$Vd,23:$Ve},o($Vf,[2,11]),o($Vf,[2,12]),o($Vm,[2,40]),o($Vm,[2,44],{5:12,7:13,29:18,3:19,4:$V1,6:$V2,8:$V3,15:$V9,18:$V4,21:$V5,23:$V6,32:$V7,34:$V8}),o($Vm,[2,45],{5:12,7:13,29:18,3:19,4:$V1,6:$V2,8:$V3,15:$V9,18:$V4,21:$V5,23:$V6,32:$V7,34:$V8}),o($Vm,[2,46],{5:12,7:13,29:18,3:19,4:$V1,6:$V2,8:$V3,15:$V9,18:$V4,21:$V5,23:$V6,32:$V7,34:$V8}),o($Vn,[2,50],{5:12,7:13,29:18,3:19,4:$V1,6:$V2,8:$V3,15:$V9,18:$V4,21:$V5,23:$V6,32:$V7,34:$V8}),o($V0,[2,7]),o($Vo,[2,16]),o($Vo,[2,20]),o($Vo,[2,21]),o($Vo,[2,22])],
201
201
  defaultActions: {17:[2,4]},
202
202
  parseError: function parseError (str, hash) {
203
203
  if (hash.recoverable) {
package/run.coffee CHANGED
@@ -8,11 +8,6 @@ builtin =
8
8
  "_log!": (arg) ->
9
9
  console.error "_log!: #{JSON.stringify arg}"
10
10
  arg
11
- "fromFILE": (fileName) ->
12
- fs.readFileSync(fileName).toString()
13
- "toFILE": ([x,fileName]) ->
14
- fs.writeFileSync fileName, x
15
- return x
16
11
  "GT": (args) ->
17
12
  [ok,_] = do ([last,args...] = args) ->
18
13
  args.reduce ([ok,last], x) ->
@@ -36,6 +31,7 @@ builtin =
36
31
  div = x // y
37
32
  rem = x %% y
38
33
  return {div,rem} if x is div * y + rem
34
+ "FDIV": ([x,y]) -> x / y
39
35
  "CONCAT": (strs) -> strs.join('')
40
36
  "true": -> true
41
37
  "false": -> false
@@ -44,7 +40,9 @@ builtin =
44
40
  "fromJSON": (x) -> JSON.parse x
45
41
  "CONS": ([x,y]) -> [x,y...]
46
42
  "SNOC": (x) ->
47
- return [x[0],x.slice 1] if x.length > 1
43
+ return [x[0],x.slice 1] if x.length > 1
44
+ "toDateMsec": (x) -> new Date(x).getTime()
45
+ "toDateStr": (x) -> new Date(x).toISOString()
48
46
 
49
47
  codes =
50
48
  "int": (x) ->
package/run.js CHANGED
@@ -19,13 +19,6 @@
19
19
  console.error(`_log!: ${JSON.stringify(arg)}`);
20
20
  return arg;
21
21
  },
22
- "fromFILE": function(fileName) {
23
- return fs.readFileSync(fileName).toString();
24
- },
25
- "toFILE": function([x, fileName]) {
26
- fs.writeFileSync(fileName, x);
27
- return x;
28
- },
29
22
  "GT": function(args) {
30
23
  var _, ok;
31
24
  [ok, _] = (function([last, ...args]) {
@@ -79,6 +72,9 @@
79
72
  return {div, rem};
80
73
  }
81
74
  },
75
+ "FDIV": function([x, y]) {
76
+ return x / y;
77
+ },
82
78
  "CONCAT": function(strs) {
83
79
  return strs.join('');
84
80
  },
@@ -104,6 +100,12 @@
104
100
  if (x.length > 1) {
105
101
  return [x[0], x.slice(1)];
106
102
  }
103
+ },
104
+ "toDateMsec": function(x) {
105
+ return new Date(x).getTime();
106
+ },
107
+ "toDateStr": function(x) {
108
+ return new Date(x).toISOString();
107
109
  }
108
110
  };
109
111