@mojir/lits 2.1.11 → 2.1.13
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/dist/cli/cli.js +492 -72
- package/dist/cli/reference/api.d.ts +4 -4
- package/dist/cli/reference/index.d.ts +7 -1
- package/dist/cli/src/tokenizer/operators.d.ts +1 -1
- package/dist/index.esm.js +454 -66
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +454 -66
- package/dist/index.js.map +1 -1
- package/dist/lits.iife.js +454 -66
- package/dist/lits.iife.js.map +1 -1
- package/dist/reference/api.d.ts +4 -4
- package/dist/reference/index.d.ts +7 -1
- package/dist/src/tokenizer/operators.d.ts +1 -1
- package/dist/testFramework.esm.js +243 -34
- package/dist/testFramework.esm.js.map +1 -1
- package/dist/testFramework.js +243 -34
- package/dist/testFramework.js.map +1 -1
- package/package.json +2 -2
package/dist/index.esm.js
CHANGED
|
@@ -397,6 +397,8 @@ function isNumber(value, options) {
|
|
|
397
397
|
if (options === void 0) { options = {}; }
|
|
398
398
|
if (typeof value !== 'number')
|
|
399
399
|
return false;
|
|
400
|
+
if (Number.isNaN(value))
|
|
401
|
+
return false;
|
|
400
402
|
if (options.integer && !Number.isInteger(value))
|
|
401
403
|
return false;
|
|
402
404
|
if (options.finite && !Number.isFinite(value))
|
|
@@ -970,6 +972,35 @@ var collectionNormalExpression = {
|
|
|
970
972
|
},
|
|
971
973
|
paramCount: 2,
|
|
972
974
|
},
|
|
975
|
+
'filteri': {
|
|
976
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
977
|
+
var _c = __read(_a, 2), coll = _c[0], fn = _c[1];
|
|
978
|
+
var executeFunction = _b.executeFunction;
|
|
979
|
+
assertColl(coll, sourceCodeInfo);
|
|
980
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
981
|
+
if (Array.isArray(coll)) {
|
|
982
|
+
var result = coll.filter(function (elem, index) { return executeFunction(fn, [elem, index], contextStack, sourceCodeInfo); });
|
|
983
|
+
return result;
|
|
984
|
+
}
|
|
985
|
+
if (isString(coll)) {
|
|
986
|
+
return coll
|
|
987
|
+
.split('')
|
|
988
|
+
.filter(function (elem, index) { return executeFunction(fn, [elem, index], contextStack, sourceCodeInfo); })
|
|
989
|
+
.join('');
|
|
990
|
+
}
|
|
991
|
+
return Object.entries(coll)
|
|
992
|
+
.filter(function (_a) {
|
|
993
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
994
|
+
return executeFunction(fn, [value, key], contextStack, sourceCodeInfo);
|
|
995
|
+
})
|
|
996
|
+
.reduce(function (result, _a) {
|
|
997
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
998
|
+
result[key] = value;
|
|
999
|
+
return result;
|
|
1000
|
+
}, {});
|
|
1001
|
+
},
|
|
1002
|
+
paramCount: 2,
|
|
1003
|
+
},
|
|
973
1004
|
'map': {
|
|
974
1005
|
evaluate: function (params, sourceCodeInfo, contextStack, _a) {
|
|
975
1006
|
var executeFunction = _a.executeFunction;
|
|
@@ -1012,6 +1043,30 @@ var collectionNormalExpression = {
|
|
|
1012
1043
|
},
|
|
1013
1044
|
paramCount: { min: 2 },
|
|
1014
1045
|
},
|
|
1046
|
+
'mapi': {
|
|
1047
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1048
|
+
var _c = __read(_a, 2), coll = _c[0], fn = _c[1];
|
|
1049
|
+
var executeFunction = _b.executeFunction;
|
|
1050
|
+
assertColl(coll, sourceCodeInfo);
|
|
1051
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1052
|
+
if (Array.isArray(coll)) {
|
|
1053
|
+
return coll.map(function (elem, index) { return executeFunction(fn, [elem, index], contextStack, sourceCodeInfo); });
|
|
1054
|
+
}
|
|
1055
|
+
if (isString(coll)) {
|
|
1056
|
+
return coll
|
|
1057
|
+
.split('')
|
|
1058
|
+
.map(function (elem, index) { return executeFunction(fn, [elem, index], contextStack, sourceCodeInfo); })
|
|
1059
|
+
.join('');
|
|
1060
|
+
}
|
|
1061
|
+
return Object.entries(coll)
|
|
1062
|
+
.reduce(function (acc, _a) {
|
|
1063
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
1064
|
+
acc[key] = executeFunction(fn, [value, key], contextStack, sourceCodeInfo);
|
|
1065
|
+
return acc;
|
|
1066
|
+
}, {});
|
|
1067
|
+
},
|
|
1068
|
+
paramCount: 2,
|
|
1069
|
+
},
|
|
1015
1070
|
'reduce': {
|
|
1016
1071
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1017
1072
|
var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
|
|
@@ -1045,6 +1100,39 @@ var collectionNormalExpression = {
|
|
|
1045
1100
|
},
|
|
1046
1101
|
paramCount: 3,
|
|
1047
1102
|
},
|
|
1103
|
+
'reducei': {
|
|
1104
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1105
|
+
var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
|
|
1106
|
+
var executeFunction = _b.executeFunction;
|
|
1107
|
+
assertColl(coll, sourceCodeInfo);
|
|
1108
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1109
|
+
assertAny(initial, sourceCodeInfo);
|
|
1110
|
+
if (typeof coll === 'string') {
|
|
1111
|
+
assertString(initial, sourceCodeInfo);
|
|
1112
|
+
if (coll.length === 0)
|
|
1113
|
+
return initial;
|
|
1114
|
+
return coll.split('').reduce(function (result, elem, index) {
|
|
1115
|
+
return executeFunction(fn, [result, elem, index], contextStack, sourceCodeInfo);
|
|
1116
|
+
}, initial);
|
|
1117
|
+
}
|
|
1118
|
+
else if (Array.isArray(coll)) {
|
|
1119
|
+
if (coll.length === 0)
|
|
1120
|
+
return initial;
|
|
1121
|
+
return coll.reduce(function (result, elem, index) {
|
|
1122
|
+
return executeFunction(fn, [result, elem, index], contextStack, sourceCodeInfo);
|
|
1123
|
+
}, initial);
|
|
1124
|
+
}
|
|
1125
|
+
else {
|
|
1126
|
+
if (Object.keys(coll).length === 0)
|
|
1127
|
+
return initial;
|
|
1128
|
+
return Object.entries(coll).reduce(function (result, _a) {
|
|
1129
|
+
var _b = __read(_a, 2), key = _b[0], elem = _b[1];
|
|
1130
|
+
return executeFunction(fn, [result, elem, key], contextStack, sourceCodeInfo);
|
|
1131
|
+
}, initial);
|
|
1132
|
+
}
|
|
1133
|
+
},
|
|
1134
|
+
paramCount: 3,
|
|
1135
|
+
},
|
|
1048
1136
|
'reduce-right': {
|
|
1049
1137
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1050
1138
|
var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
|
|
@@ -1077,6 +1165,38 @@ var collectionNormalExpression = {
|
|
|
1077
1165
|
},
|
|
1078
1166
|
paramCount: 3,
|
|
1079
1167
|
},
|
|
1168
|
+
'reducei-right': {
|
|
1169
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1170
|
+
var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
|
|
1171
|
+
var executeFunction = _b.executeFunction;
|
|
1172
|
+
assertColl(coll, sourceCodeInfo);
|
|
1173
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1174
|
+
assertAny(initial, sourceCodeInfo);
|
|
1175
|
+
if (typeof coll === 'string') {
|
|
1176
|
+
if (coll.length === 0)
|
|
1177
|
+
return initial;
|
|
1178
|
+
return coll.split('').reduceRight(function (result, elem, index) {
|
|
1179
|
+
return executeFunction(fn, [result, elem, index], contextStack, sourceCodeInfo);
|
|
1180
|
+
}, initial);
|
|
1181
|
+
}
|
|
1182
|
+
else if (Array.isArray(coll)) {
|
|
1183
|
+
if (coll.length === 0)
|
|
1184
|
+
return initial;
|
|
1185
|
+
return coll.reduceRight(function (result, elem, index) {
|
|
1186
|
+
return executeFunction(fn, [result, elem, index], contextStack, sourceCodeInfo);
|
|
1187
|
+
}, initial);
|
|
1188
|
+
}
|
|
1189
|
+
else {
|
|
1190
|
+
if (Object.keys(coll).length === 0)
|
|
1191
|
+
return initial;
|
|
1192
|
+
return Object.entries(coll).reduceRight(function (result, _a) {
|
|
1193
|
+
var _b = __read(_a, 2), key = _b[0], elem = _b[1];
|
|
1194
|
+
return executeFunction(fn, [result, elem, key], contextStack, sourceCodeInfo);
|
|
1195
|
+
}, initial);
|
|
1196
|
+
}
|
|
1197
|
+
},
|
|
1198
|
+
paramCount: 3,
|
|
1199
|
+
},
|
|
1080
1200
|
'reductions': {
|
|
1081
1201
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1082
1202
|
var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
|
|
@@ -1123,6 +1243,52 @@ var collectionNormalExpression = {
|
|
|
1123
1243
|
},
|
|
1124
1244
|
paramCount: 3,
|
|
1125
1245
|
},
|
|
1246
|
+
'reductionsi': {
|
|
1247
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1248
|
+
var _c = __read(_a, 3), coll = _c[0], fn = _c[1], initial = _c[2];
|
|
1249
|
+
var executeFunction = _b.executeFunction;
|
|
1250
|
+
assertColl(coll, sourceCodeInfo);
|
|
1251
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1252
|
+
assertAny(initial, sourceCodeInfo);
|
|
1253
|
+
assertAny(initial, sourceCodeInfo);
|
|
1254
|
+
if (typeof coll === 'string') {
|
|
1255
|
+
assertString(initial, sourceCodeInfo);
|
|
1256
|
+
if (coll.length === 0)
|
|
1257
|
+
return [initial];
|
|
1258
|
+
var resultArray_4 = [initial];
|
|
1259
|
+
coll.split('').reduce(function (result, elem, index) {
|
|
1260
|
+
var newVal = executeFunction(fn, [result, elem, index], contextStack, sourceCodeInfo);
|
|
1261
|
+
resultArray_4.push(newVal);
|
|
1262
|
+
return newVal;
|
|
1263
|
+
}, initial);
|
|
1264
|
+
return resultArray_4;
|
|
1265
|
+
}
|
|
1266
|
+
else if (Array.isArray(coll)) {
|
|
1267
|
+
if (coll.length === 0)
|
|
1268
|
+
return [initial];
|
|
1269
|
+
var resultArray_5 = [initial];
|
|
1270
|
+
coll.reduce(function (result, elem, index) {
|
|
1271
|
+
var newVal = executeFunction(fn, [result, elem, index], contextStack, sourceCodeInfo);
|
|
1272
|
+
resultArray_5.push(newVal);
|
|
1273
|
+
return newVal;
|
|
1274
|
+
}, initial);
|
|
1275
|
+
return resultArray_5;
|
|
1276
|
+
}
|
|
1277
|
+
else {
|
|
1278
|
+
if (Object.keys(coll).length === 0)
|
|
1279
|
+
return [initial];
|
|
1280
|
+
var resultArray_6 = [initial];
|
|
1281
|
+
Object.entries(coll).reduce(function (result, _a) {
|
|
1282
|
+
var _b = __read(_a, 2), key = _b[0], elem = _b[1];
|
|
1283
|
+
var newVal = executeFunction(fn, [result, elem, key], contextStack, sourceCodeInfo);
|
|
1284
|
+
resultArray_6.push(newVal);
|
|
1285
|
+
return newVal;
|
|
1286
|
+
}, initial);
|
|
1287
|
+
return resultArray_6;
|
|
1288
|
+
}
|
|
1289
|
+
},
|
|
1290
|
+
paramCount: 3,
|
|
1291
|
+
},
|
|
1126
1292
|
'get': {
|
|
1127
1293
|
evaluate: function (params, sourceCodeInfo) {
|
|
1128
1294
|
var _a = __read(params, 2), coll = _a[0], key = _a[1];
|
|
@@ -1376,7 +1542,7 @@ var collectionNormalExpression = {
|
|
|
1376
1542
|
};
|
|
1377
1543
|
|
|
1378
1544
|
var arrayNormalExpression = {
|
|
1379
|
-
range: {
|
|
1545
|
+
'range': {
|
|
1380
1546
|
evaluate: function (params, sourceCodeInfo) {
|
|
1381
1547
|
var _a = __read(params, 3), first = _a[0], second = _a[1], third = _a[2];
|
|
1382
1548
|
var from;
|
|
@@ -1414,7 +1580,7 @@ var arrayNormalExpression = {
|
|
|
1414
1580
|
},
|
|
1415
1581
|
paramCount: { min: 1, max: 3 },
|
|
1416
1582
|
},
|
|
1417
|
-
repeat: {
|
|
1583
|
+
'repeat': {
|
|
1418
1584
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1419
1585
|
var _b = __read(_a, 2), value = _b[0], count = _b[1];
|
|
1420
1586
|
assertNumber(count, sourceCodeInfo, { integer: true, nonNegative: true });
|
|
@@ -1425,7 +1591,7 @@ var arrayNormalExpression = {
|
|
|
1425
1591
|
},
|
|
1426
1592
|
paramCount: 2,
|
|
1427
1593
|
},
|
|
1428
|
-
flatten: {
|
|
1594
|
+
'flatten': {
|
|
1429
1595
|
evaluate: function (_a, sourceCodeInfo) {
|
|
1430
1596
|
var _b = __read(_a, 2), seq = _b[0], depth = _b[1];
|
|
1431
1597
|
assertArray(seq, sourceCodeInfo);
|
|
@@ -1436,7 +1602,7 @@ var arrayNormalExpression = {
|
|
|
1436
1602
|
},
|
|
1437
1603
|
paramCount: { min: 1, max: 2 },
|
|
1438
1604
|
},
|
|
1439
|
-
mapcat: {
|
|
1605
|
+
'mapcat': {
|
|
1440
1606
|
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1441
1607
|
var _c = __read(_a, 2), arr = _c[0], fn = _c[1];
|
|
1442
1608
|
var executeFunction = _b.executeFunction;
|
|
@@ -1446,6 +1612,38 @@ var arrayNormalExpression = {
|
|
|
1446
1612
|
},
|
|
1447
1613
|
paramCount: 2,
|
|
1448
1614
|
},
|
|
1615
|
+
'moving-fn': {
|
|
1616
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1617
|
+
var _c = __read(_a, 3), arr = _c[0], windowSize = _c[1], fn = _c[2];
|
|
1618
|
+
var executeFunction = _b.executeFunction;
|
|
1619
|
+
assertArray(arr, sourceCodeInfo);
|
|
1620
|
+
assertNumber(windowSize, sourceCodeInfo, { integer: true, lte: arr.length });
|
|
1621
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1622
|
+
var result = [];
|
|
1623
|
+
for (var i = 0; i <= arr.length - windowSize; i++) {
|
|
1624
|
+
var window_1 = arr.slice(i, i + windowSize);
|
|
1625
|
+
var value = executeFunction(fn, [window_1], contextStack, sourceCodeInfo);
|
|
1626
|
+
result.push(value);
|
|
1627
|
+
}
|
|
1628
|
+
return result;
|
|
1629
|
+
},
|
|
1630
|
+
paramCount: 3,
|
|
1631
|
+
},
|
|
1632
|
+
'running-fn': {
|
|
1633
|
+
evaluate: function (_a, sourceCodeInfo, contextStack, _b) {
|
|
1634
|
+
var _c = __read(_a, 2), arr = _c[0], fn = _c[1];
|
|
1635
|
+
var executeFunction = _b.executeFunction;
|
|
1636
|
+
assertArray(arr, sourceCodeInfo);
|
|
1637
|
+
assertFunctionLike(fn, sourceCodeInfo);
|
|
1638
|
+
var result = [];
|
|
1639
|
+
for (var i = 0; i < arr.length; i += 1) {
|
|
1640
|
+
var subArr = arr.slice(0, i + 1);
|
|
1641
|
+
result.push(executeFunction(fn, [subArr], contextStack, sourceCodeInfo));
|
|
1642
|
+
}
|
|
1643
|
+
return result;
|
|
1644
|
+
},
|
|
1645
|
+
paramCount: 2,
|
|
1646
|
+
},
|
|
1449
1647
|
};
|
|
1450
1648
|
|
|
1451
1649
|
var sequenceNormalExpression = {
|
|
@@ -2177,7 +2375,7 @@ function isVector(vector) {
|
|
|
2177
2375
|
if (vectors.has(vector)) {
|
|
2178
2376
|
return true;
|
|
2179
2377
|
}
|
|
2180
|
-
if (vector.every(function (elem) { return isNumber(elem
|
|
2378
|
+
if (vector.every(function (elem) { return isNumber(elem); })) {
|
|
2181
2379
|
annotatedArrays.add(vector);
|
|
2182
2380
|
vectors.add(vector);
|
|
2183
2381
|
return true;
|
|
@@ -2286,7 +2484,7 @@ function isMatrix(matrix) {
|
|
|
2286
2484
|
if (row.length !== nbrOfCols) {
|
|
2287
2485
|
return false;
|
|
2288
2486
|
}
|
|
2289
|
-
if (row.some(function (cell) { return !isNumber(cell
|
|
2487
|
+
if (row.some(function (cell) { return !isNumber(cell); })) {
|
|
2290
2488
|
return false;
|
|
2291
2489
|
}
|
|
2292
2490
|
}
|
|
@@ -3819,14 +4017,6 @@ var predicatesNormalExpression = {
|
|
|
3819
4017
|
},
|
|
3820
4018
|
paramCount: 1,
|
|
3821
4019
|
},
|
|
3822
|
-
'nan?': {
|
|
3823
|
-
evaluate: function (_a, sourceCodeInfo) {
|
|
3824
|
-
var _b = __read(_a, 1), value = _b[0];
|
|
3825
|
-
assertNumber(value, sourceCodeInfo);
|
|
3826
|
-
return Number.isNaN(value);
|
|
3827
|
-
},
|
|
3828
|
-
paramCount: 1,
|
|
3829
|
-
},
|
|
3830
4020
|
'positive-infinity?': {
|
|
3831
4021
|
evaluate: function (_a, sourceCodeInfo) {
|
|
3832
4022
|
var _b = __read(_a, 1), value = _b[0];
|
|
@@ -12543,8 +12733,13 @@ function evaluateNode(node, contextStack) {
|
|
|
12543
12733
|
return contextStack.evaluateSymbol(node);
|
|
12544
12734
|
case NodeTypes.ReservedSymbol:
|
|
12545
12735
|
return evaluateReservedSymbol(node);
|
|
12546
|
-
case NodeTypes.NormalExpression:
|
|
12547
|
-
|
|
12736
|
+
case NodeTypes.NormalExpression: {
|
|
12737
|
+
var result = evaluateNormalExpression(node, contextStack);
|
|
12738
|
+
if (typeof result === 'number' && Number.isNaN(result)) {
|
|
12739
|
+
throw new LitsError('Number is NaN', node[2]);
|
|
12740
|
+
}
|
|
12741
|
+
return annotate(result);
|
|
12742
|
+
}
|
|
12548
12743
|
case NodeTypes.SpecialExpression:
|
|
12549
12744
|
return annotate(evaluateSpecialExpression(node, contextStack));
|
|
12550
12745
|
/* v8 ignore next 2 */
|
|
@@ -12936,6 +13131,8 @@ var binaryOperators = [
|
|
|
12936
13131
|
'|>', // pipe
|
|
12937
13132
|
];
|
|
12938
13133
|
var otherOperators = [
|
|
13134
|
+
'?', // conditional operator
|
|
13135
|
+
':', // conditional operator
|
|
12939
13136
|
'->', // lambda
|
|
12940
13137
|
'...', // rest
|
|
12941
13138
|
'.', // property accessor
|
|
@@ -12945,17 +13142,12 @@ var otherOperators = [
|
|
|
12945
13142
|
];
|
|
12946
13143
|
var symbolicOperators = __spreadArray(__spreadArray([], __read(binaryOperators), false), __read(otherOperators), false);
|
|
12947
13144
|
var nonFunctionOperators = [
|
|
12948
|
-
'??',
|
|
12949
|
-
'&&',
|
|
12950
|
-
'||',
|
|
12951
13145
|
'comment',
|
|
12952
13146
|
'cond',
|
|
12953
13147
|
'def',
|
|
12954
13148
|
'defined?',
|
|
12955
|
-
// 'defn',
|
|
12956
13149
|
'do',
|
|
12957
13150
|
'doseq',
|
|
12958
|
-
// 'fn',
|
|
12959
13151
|
'if',
|
|
12960
13152
|
'let',
|
|
12961
13153
|
'loop',
|
|
@@ -13533,8 +13725,9 @@ function untokenize(tokenStream) {
|
|
|
13533
13725
|
}, '');
|
|
13534
13726
|
}
|
|
13535
13727
|
|
|
13536
|
-
var exponentiationPrecedence =
|
|
13537
|
-
var binaryFunctionalOperatorPrecedence =
|
|
13728
|
+
var exponentiationPrecedence = 12;
|
|
13729
|
+
var binaryFunctionalOperatorPrecedence = 3;
|
|
13730
|
+
var conditionalOperatorPrecedence = 1;
|
|
13538
13731
|
var placeholderRegexp = /^\$([1-9]\d?)?$/;
|
|
13539
13732
|
function withSourceCodeInfo(node, sourceCodeInfo) {
|
|
13540
13733
|
if (sourceCodeInfo) {
|
|
@@ -13549,38 +13742,39 @@ function getPrecedence(operatorSign, sourceCodeInfo) {
|
|
|
13549
13742
|
case '*': // multiplication
|
|
13550
13743
|
case '/': // division
|
|
13551
13744
|
case '%': // remainder
|
|
13552
|
-
return
|
|
13745
|
+
return 11;
|
|
13553
13746
|
case '+': // addition
|
|
13554
13747
|
case '-': // subtraction
|
|
13555
|
-
return
|
|
13748
|
+
return 10;
|
|
13556
13749
|
case '<<': // left shift
|
|
13557
13750
|
case '>>': // signed right shift
|
|
13558
13751
|
case '>>>': // unsigned right shift
|
|
13559
|
-
return
|
|
13752
|
+
return 9;
|
|
13560
13753
|
case '++': // string concatenation
|
|
13561
|
-
return
|
|
13754
|
+
return 8;
|
|
13562
13755
|
case '<': // less than
|
|
13563
13756
|
case '<=': // less than or equal
|
|
13564
13757
|
case '≤': // less than or equal
|
|
13565
13758
|
case '>': // greater than
|
|
13566
13759
|
case '>=': // greater than or equal
|
|
13567
13760
|
case '≥': // greater than or equal
|
|
13568
|
-
return
|
|
13761
|
+
return 7;
|
|
13569
13762
|
case '=': // equal
|
|
13570
13763
|
case '!=': // not equal
|
|
13571
13764
|
case '≠': // not equal
|
|
13572
|
-
return
|
|
13765
|
+
return 6;
|
|
13573
13766
|
case '&': // bitwise AND
|
|
13574
13767
|
case 'xor': // bitwise XOR
|
|
13575
13768
|
case '|': // bitwise OR
|
|
13576
|
-
return
|
|
13769
|
+
return 5;
|
|
13577
13770
|
case '&&': // logical AND
|
|
13578
13771
|
case '||': // logical OR
|
|
13579
13772
|
case '??': // nullish coalescing
|
|
13580
|
-
return
|
|
13773
|
+
return 4;
|
|
13774
|
+
// leave room for binaryFunctionalOperatorPrecedence = 3
|
|
13581
13775
|
case '|>': // pipe
|
|
13582
|
-
return
|
|
13583
|
-
// leave room for
|
|
13776
|
+
return 2;
|
|
13777
|
+
// leave room for conditionalOperatorPrecedence = 1
|
|
13584
13778
|
/* v8 ignore next 2 */
|
|
13585
13779
|
default:
|
|
13586
13780
|
throw new LitsError("Unknown binary operator: ".concat(operatorSign), sourceCodeInfo);
|
|
@@ -13628,13 +13822,15 @@ function fromBinaryOperatorToNode(operator, symbolNode, left, right, sourceCodeI
|
|
|
13628
13822
|
case '||':
|
|
13629
13823
|
case '??':
|
|
13630
13824
|
return withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes[operatorName], [left, right]]], sourceCodeInfo);
|
|
13631
|
-
/* v8 ignore next
|
|
13825
|
+
/* v8 ignore next 11 */
|
|
13632
13826
|
case '.':
|
|
13633
13827
|
case ';':
|
|
13634
13828
|
case ':=':
|
|
13635
13829
|
case ',':
|
|
13636
13830
|
case '->':
|
|
13637
13831
|
case '...':
|
|
13832
|
+
case '?':
|
|
13833
|
+
case ':':
|
|
13638
13834
|
throw new LitsError("Unknown binary operator: ".concat(operatorName), sourceCodeInfo);
|
|
13639
13835
|
default:
|
|
13640
13836
|
throw new LitsError("Unknown binary operator: ".concat(operatorName), sourceCodeInfo);
|
|
@@ -13750,6 +13946,19 @@ var Parser = /** @class */ (function () {
|
|
|
13750
13946
|
}
|
|
13751
13947
|
left = createNamedNormalExpressionNode(operatorSymbol, [left, right], operator[2]);
|
|
13752
13948
|
}
|
|
13949
|
+
else if ((operator === null || operator === void 0 ? void 0 : operator[1]) === '?') {
|
|
13950
|
+
if (conditionalOperatorPrecedence <= precedence) {
|
|
13951
|
+
break;
|
|
13952
|
+
}
|
|
13953
|
+
this.advance();
|
|
13954
|
+
var trueNode = this.parseExpression();
|
|
13955
|
+
if (!isOperatorToken(this.peek(), ':')) {
|
|
13956
|
+
throw new LitsError('Expected :', this.peekSourceCodeInfo());
|
|
13957
|
+
}
|
|
13958
|
+
this.advance();
|
|
13959
|
+
var falseNode = this.parseExpression();
|
|
13960
|
+
left = withSourceCodeInfo([NodeTypes.SpecialExpression, [specialExpressionTypes.if, [left, trueNode, falseNode]]], left[2]);
|
|
13961
|
+
}
|
|
13753
13962
|
else {
|
|
13754
13963
|
break;
|
|
13755
13964
|
}
|
|
@@ -14936,10 +15145,15 @@ function getVectorReductionNames(name) {
|
|
|
14936
15145
|
var api = {
|
|
14937
15146
|
collection: [
|
|
14938
15147
|
'filter',
|
|
15148
|
+
'filteri',
|
|
14939
15149
|
'map',
|
|
15150
|
+
'mapi',
|
|
14940
15151
|
'reduce',
|
|
15152
|
+
'reducei',
|
|
14941
15153
|
'reduce-right',
|
|
15154
|
+
'reducei-right',
|
|
14942
15155
|
'reductions',
|
|
15156
|
+
'reductionsi',
|
|
14943
15157
|
'count',
|
|
14944
15158
|
'get',
|
|
14945
15159
|
'get-in',
|
|
@@ -14960,6 +15174,8 @@ var api = {
|
|
|
14960
15174
|
'repeat',
|
|
14961
15175
|
'flatten',
|
|
14962
15176
|
'mapcat',
|
|
15177
|
+
'moving-fn',
|
|
15178
|
+
'running-fn',
|
|
14963
15179
|
],
|
|
14964
15180
|
sequence: [
|
|
14965
15181
|
'nth',
|
|
@@ -15099,7 +15315,6 @@ var api = {
|
|
|
15099
15315
|
'even?',
|
|
15100
15316
|
'odd?',
|
|
15101
15317
|
'finite?',
|
|
15102
|
-
'nan?',
|
|
15103
15318
|
'negative-infinity?',
|
|
15104
15319
|
'positive-infinity?',
|
|
15105
15320
|
'false?',
|
|
@@ -15436,7 +15651,7 @@ function getOperatorArgs(a, b) {
|
|
|
15436
15651
|
}
|
|
15437
15652
|
|
|
15438
15653
|
var arrayReference = {
|
|
15439
|
-
range: {
|
|
15654
|
+
'range': {
|
|
15440
15655
|
title: 'range',
|
|
15441
15656
|
category: 'Array',
|
|
15442
15657
|
linkName: 'range',
|
|
@@ -15461,7 +15676,7 @@ var arrayReference = {
|
|
|
15461
15676
|
"\nrange(\n 0.25, // start value\n 1, // end value (exclusive)\n 0.25, // step value\n)",
|
|
15462
15677
|
],
|
|
15463
15678
|
},
|
|
15464
|
-
repeat: {
|
|
15679
|
+
'repeat': {
|
|
15465
15680
|
title: 'repeat',
|
|
15466
15681
|
category: 'Array',
|
|
15467
15682
|
linkName: 'repeat',
|
|
@@ -15480,7 +15695,7 @@ var arrayReference = {
|
|
|
15480
15695
|
'"Albert" repeat 5',
|
|
15481
15696
|
],
|
|
15482
15697
|
},
|
|
15483
|
-
flatten: {
|
|
15698
|
+
'flatten': {
|
|
15484
15699
|
title: 'flatten',
|
|
15485
15700
|
category: 'Array',
|
|
15486
15701
|
linkName: 'flatten',
|
|
@@ -15504,7 +15719,7 @@ var arrayReference = {
|
|
|
15504
15719
|
],
|
|
15505
15720
|
noOperatorDocumentation: true,
|
|
15506
15721
|
},
|
|
15507
|
-
mapcat: {
|
|
15722
|
+
'mapcat': {
|
|
15508
15723
|
title: 'mapcat',
|
|
15509
15724
|
category: 'Array',
|
|
15510
15725
|
linkName: 'mapcat',
|
|
@@ -15529,6 +15744,60 @@ var arrayReference = {
|
|
|
15529
15744
|
"\nmapcat(\n [[1, 2], [2, 2], [2, 3]],\n -> $ remove even?\n)",
|
|
15530
15745
|
],
|
|
15531
15746
|
},
|
|
15747
|
+
'moving-fn': {
|
|
15748
|
+
title: 'moving-fn',
|
|
15749
|
+
category: 'Array',
|
|
15750
|
+
linkName: 'moving-fn',
|
|
15751
|
+
returns: {
|
|
15752
|
+
type: 'array',
|
|
15753
|
+
},
|
|
15754
|
+
args: {
|
|
15755
|
+
arr: {
|
|
15756
|
+
type: 'array',
|
|
15757
|
+
},
|
|
15758
|
+
windowSize: {
|
|
15759
|
+
type: 'number',
|
|
15760
|
+
description: 'The size of the moving window.',
|
|
15761
|
+
},
|
|
15762
|
+
fn: {
|
|
15763
|
+
type: 'function',
|
|
15764
|
+
},
|
|
15765
|
+
},
|
|
15766
|
+
variants: [{
|
|
15767
|
+
argumentNames: ['arr', 'windowSize', 'fn'],
|
|
15768
|
+
}],
|
|
15769
|
+
description: 'Returns the result of applying $fn to each moving window of size $windowSize in $arr.',
|
|
15770
|
+
examples: [
|
|
15771
|
+
'moving-fn([1, 2, 3], 2, vec:sum)',
|
|
15772
|
+
'moving-fn([1, 2, 3], 1, vec:sum)',
|
|
15773
|
+
'moving-fn([1, 2, 3], 3, vec:sum)',
|
|
15774
|
+
],
|
|
15775
|
+
},
|
|
15776
|
+
'running-fn': {
|
|
15777
|
+
title: 'running-fn',
|
|
15778
|
+
category: 'Array',
|
|
15779
|
+
linkName: 'running-fn',
|
|
15780
|
+
returns: {
|
|
15781
|
+
type: 'array',
|
|
15782
|
+
},
|
|
15783
|
+
args: {
|
|
15784
|
+
a: {
|
|
15785
|
+
type: 'array',
|
|
15786
|
+
},
|
|
15787
|
+
b: {
|
|
15788
|
+
type: 'function',
|
|
15789
|
+
},
|
|
15790
|
+
},
|
|
15791
|
+
variants: [{
|
|
15792
|
+
argumentNames: ['a', 'b'],
|
|
15793
|
+
}],
|
|
15794
|
+
description: 'Returns the result of applying $b to each element of $a.',
|
|
15795
|
+
examples: [
|
|
15796
|
+
'running-fn([1, 2, 3], vec:sum)',
|
|
15797
|
+
'running-fn([1, 2, 3], vec:max)',
|
|
15798
|
+
'running-fn([1, 2, 3], vec:min)',
|
|
15799
|
+
],
|
|
15800
|
+
},
|
|
15532
15801
|
};
|
|
15533
15802
|
|
|
15534
15803
|
var assertReference = {
|
|
@@ -16189,6 +16458,32 @@ var collectionReference = {
|
|
|
16189
16458
|
"\nfilter(\n { a := 1, b := 2 },\n odd?\n)",
|
|
16190
16459
|
],
|
|
16191
16460
|
},
|
|
16461
|
+
'filteri': {
|
|
16462
|
+
title: 'filteri',
|
|
16463
|
+
category: 'Collection',
|
|
16464
|
+
linkName: 'filteri',
|
|
16465
|
+
returns: {
|
|
16466
|
+
type: 'collection',
|
|
16467
|
+
},
|
|
16468
|
+
args: {
|
|
16469
|
+
a: {
|
|
16470
|
+
type: 'collection',
|
|
16471
|
+
},
|
|
16472
|
+
b: {
|
|
16473
|
+
type: 'function',
|
|
16474
|
+
description: 'The function to call for each element in the collection. The function should take two arguments: the element itself and the index.',
|
|
16475
|
+
},
|
|
16476
|
+
},
|
|
16477
|
+
variants: [
|
|
16478
|
+
{ argumentNames: ['a', 'b'] },
|
|
16479
|
+
],
|
|
16480
|
+
description: 'Creates a new collection with all elements that pass the test implemented by $b. The function is called for each element in the collection, and it should take two arguments: the element itself and the index.',
|
|
16481
|
+
examples: [
|
|
16482
|
+
'filteri([1, 2, 3], (x, i) -> i % 2 = 0)',
|
|
16483
|
+
'filteri([1, 2, 3], (x, i) -> x % 2 = 0)',
|
|
16484
|
+
'filteri([1, 2, 3], (x, i) -> x + i > 3)',
|
|
16485
|
+
],
|
|
16486
|
+
},
|
|
16192
16487
|
'map': {
|
|
16193
16488
|
title: 'map',
|
|
16194
16489
|
category: 'Collection',
|
|
@@ -16217,6 +16512,34 @@ var collectionReference = {
|
|
|
16217
16512
|
'map({ a := 1, b := 2 }, { a := 10, b := 20 }, +)',
|
|
16218
16513
|
],
|
|
16219
16514
|
},
|
|
16515
|
+
'mapi': {
|
|
16516
|
+
title: 'mapi',
|
|
16517
|
+
category: 'Collection',
|
|
16518
|
+
linkName: 'mapi',
|
|
16519
|
+
returns: {
|
|
16520
|
+
type: 'collection',
|
|
16521
|
+
},
|
|
16522
|
+
args: {
|
|
16523
|
+
a: {
|
|
16524
|
+
type: 'collection',
|
|
16525
|
+
},
|
|
16526
|
+
b: {
|
|
16527
|
+
type: 'function',
|
|
16528
|
+
description: 'The function to call for each element in the collection. The function should take two arguments: the element itself and the index.',
|
|
16529
|
+
},
|
|
16530
|
+
},
|
|
16531
|
+
variants: [
|
|
16532
|
+
{ argumentNames: ['a', 'b'] },
|
|
16533
|
+
],
|
|
16534
|
+
description: 'Creates a new collection populated with the results of calling $b on every element in $a. The function is called for each element in the collection, and it should take two arguments: the element itself and the index.',
|
|
16535
|
+
examples: [
|
|
16536
|
+
'mapi([1, 2, 3], (x, i) -> x + i)',
|
|
16537
|
+
'mapi([1, 2, 3], (x, i) -> x * i)',
|
|
16538
|
+
'mapi([1, 2, 3], (x, i) -> x - i)',
|
|
16539
|
+
'mapi([1, 2, 3], (x, i) -> x / i)',
|
|
16540
|
+
'mapi([1, 2, 3], (x, i) -> x % inc(i))',
|
|
16541
|
+
],
|
|
16542
|
+
},
|
|
16220
16543
|
'reduce': {
|
|
16221
16544
|
title: 'reduce',
|
|
16222
16545
|
category: 'Collection',
|
|
@@ -16273,12 +16596,73 @@ var collectionReference = {
|
|
|
16273
16596
|
'reduce-right({ a := 1, b := 2 }, +, 0)',
|
|
16274
16597
|
],
|
|
16275
16598
|
},
|
|
16599
|
+
'reducei-right': {
|
|
16600
|
+
title: 'reducei-right',
|
|
16601
|
+
category: 'Collection',
|
|
16602
|
+
linkName: 'reducei-right',
|
|
16603
|
+
returns: {
|
|
16604
|
+
type: 'any',
|
|
16605
|
+
},
|
|
16606
|
+
args: {
|
|
16607
|
+
coll: {
|
|
16608
|
+
type: 'collection',
|
|
16609
|
+
},
|
|
16610
|
+
fun: {
|
|
16611
|
+
type: 'function',
|
|
16612
|
+
description: 'The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index.',
|
|
16613
|
+
},
|
|
16614
|
+
initial: {
|
|
16615
|
+
type: 'any',
|
|
16616
|
+
description: 'The initial value to use as the accumulator.',
|
|
16617
|
+
},
|
|
16618
|
+
},
|
|
16619
|
+
variants: [
|
|
16620
|
+
{ argumentNames: ['coll', 'fun', 'initial'] },
|
|
16621
|
+
],
|
|
16622
|
+
description: 'Runs $fun function on each element of the $coll (starting from the last item), passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.',
|
|
16623
|
+
examples: [
|
|
16624
|
+
'reducei-right([1, 2, 3], (acc, x, i) -> acc + x + i, 0)',
|
|
16625
|
+
'reducei-right("Albert", (acc, x, i) -> acc ++ x ++ i, "")',
|
|
16626
|
+
'reducei-right({ a := 1, b := 2 }, -> $1 ++ $3, "")',
|
|
16627
|
+
],
|
|
16628
|
+
},
|
|
16629
|
+
'reducei': {
|
|
16630
|
+
title: 'reducei',
|
|
16631
|
+
category: 'Collection',
|
|
16632
|
+
linkName: 'reducei',
|
|
16633
|
+
returns: {
|
|
16634
|
+
type: 'any',
|
|
16635
|
+
},
|
|
16636
|
+
args: {
|
|
16637
|
+
coll: {
|
|
16638
|
+
type: 'collection',
|
|
16639
|
+
},
|
|
16640
|
+
fun: {
|
|
16641
|
+
type: 'function',
|
|
16642
|
+
description: 'The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index.',
|
|
16643
|
+
},
|
|
16644
|
+
initial: {
|
|
16645
|
+
type: 'any',
|
|
16646
|
+
description: 'The initial value to use as the accumulator.',
|
|
16647
|
+
},
|
|
16648
|
+
},
|
|
16649
|
+
variants: [
|
|
16650
|
+
{ argumentNames: ['coll', 'fun', 'initial'] },
|
|
16651
|
+
],
|
|
16652
|
+
description: 'Runs $fun function on each element of the $coll, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the $coll is a single value. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.',
|
|
16653
|
+
examples: [
|
|
16654
|
+
'reducei([1, 2, 3], (acc, x, i) -> acc + x + i, 0)',
|
|
16655
|
+
'reducei("Albert", (acc, x, i) -> acc ++ x ++ i, "")',
|
|
16656
|
+
'reducei({ a := 1, b := 2 }, -> $1 ++ $3, "")',
|
|
16657
|
+
],
|
|
16658
|
+
},
|
|
16276
16659
|
'reductions': {
|
|
16277
16660
|
title: 'reductions',
|
|
16278
16661
|
category: 'Collection',
|
|
16279
16662
|
linkName: 'reductions',
|
|
16280
16663
|
returns: {
|
|
16281
16664
|
type: 'any',
|
|
16665
|
+
array: true,
|
|
16282
16666
|
},
|
|
16283
16667
|
args: {
|
|
16284
16668
|
fun: {
|
|
@@ -16303,6 +16687,37 @@ var collectionReference = {
|
|
|
16303
16687
|
"\nreductions(\n [1, 2, 3, 4, 5, 6, 7, 8, 9],\n (result, value) -> result + if even?(value) then value else 0 end,\n 0\n)",
|
|
16304
16688
|
],
|
|
16305
16689
|
},
|
|
16690
|
+
'reductionsi': {
|
|
16691
|
+
title: 'reductionsi',
|
|
16692
|
+
category: 'Collection',
|
|
16693
|
+
linkName: 'reductionsi',
|
|
16694
|
+
returns: {
|
|
16695
|
+
type: 'any',
|
|
16696
|
+
array: true,
|
|
16697
|
+
},
|
|
16698
|
+
args: {
|
|
16699
|
+
coll: {
|
|
16700
|
+
type: 'collection',
|
|
16701
|
+
},
|
|
16702
|
+
fun: {
|
|
16703
|
+
type: 'function',
|
|
16704
|
+
description: 'The function to call for each element in the collection. The function should take three arguments: the accumulator, the element itself, and the index.',
|
|
16705
|
+
},
|
|
16706
|
+
initial: {
|
|
16707
|
+
type: 'any',
|
|
16708
|
+
description: 'The initial value to use as the accumulator.',
|
|
16709
|
+
},
|
|
16710
|
+
},
|
|
16711
|
+
variants: [
|
|
16712
|
+
{ argumentNames: ['coll', 'fun', 'initial'] },
|
|
16713
|
+
],
|
|
16714
|
+
description: 'Returns an array of the intermediate values of the reduction (see `reduce`) of $coll by $fun. The function is called for each element in the collection, and it should take three arguments: the accumulator, the element itself, and the index.',
|
|
16715
|
+
examples: [
|
|
16716
|
+
'reductionsi([1, 2, 3], (acc, x, i) -> acc + x + i, 0)',
|
|
16717
|
+
'reductionsi("Albert", (acc, x, i) -> acc ++ x ++ i, "")',
|
|
16718
|
+
'reductionsi({ a := 1, b := 2 }, -> $1 ++ $3, "")',
|
|
16719
|
+
],
|
|
16720
|
+
},
|
|
16306
16721
|
'count': {
|
|
16307
16722
|
title: 'count',
|
|
16308
16723
|
category: 'Collection',
|
|
@@ -24767,30 +25182,6 @@ var predicateReference = {
|
|
|
24767
25182
|
'finite?(1.0)',
|
|
24768
25183
|
'finite?(1 / 0)',
|
|
24769
25184
|
'finite?(-1 / 0)',
|
|
24770
|
-
'finite?(sqrt(-1))',
|
|
24771
|
-
],
|
|
24772
|
-
},
|
|
24773
|
-
'nan?': {
|
|
24774
|
-
title: 'nan?',
|
|
24775
|
-
category: 'Predicate',
|
|
24776
|
-
linkName: 'nan-question',
|
|
24777
|
-
returns: {
|
|
24778
|
-
type: 'boolean',
|
|
24779
|
-
},
|
|
24780
|
-
args: {
|
|
24781
|
-
x: {
|
|
24782
|
-
type: 'number',
|
|
24783
|
-
},
|
|
24784
|
-
},
|
|
24785
|
-
variants: [
|
|
24786
|
-
{ argumentNames: ['x'] },
|
|
24787
|
-
],
|
|
24788
|
-
description: 'Returns `true` if $x is NaN (! a number), otherwise `false`.',
|
|
24789
|
-
examples: [
|
|
24790
|
-
'nan?(1.0)',
|
|
24791
|
-
'nan?(1 / 0)',
|
|
24792
|
-
'nan?(-1 / 0)',
|
|
24793
|
-
'nan?(sqrt(-1))',
|
|
24794
25185
|
],
|
|
24795
25186
|
},
|
|
24796
25187
|
'negative-infinity?': {
|
|
@@ -24813,7 +25204,6 @@ var predicateReference = {
|
|
|
24813
25204
|
'negative-infinity?(1.0)',
|
|
24814
25205
|
'negative-infinity?(1 / 0)',
|
|
24815
25206
|
'negative-infinity?(-1 / 0)',
|
|
24816
|
-
'negative-infinity?(sqrt(-1))',
|
|
24817
25207
|
],
|
|
24818
25208
|
},
|
|
24819
25209
|
'positive-infinity?': {
|
|
@@ -24836,7 +25226,6 @@ var predicateReference = {
|
|
|
24836
25226
|
'positive-infinity?(1.0)',
|
|
24837
25227
|
'positive-infinity?(1 / 0)',
|
|
24838
25228
|
'positive-infinity?(-1 / 0)',
|
|
24839
|
-
'positive-infinity?(sqrt(-1))',
|
|
24840
25229
|
],
|
|
24841
25230
|
},
|
|
24842
25231
|
'false?': {
|
|
@@ -30668,7 +31057,6 @@ var numberTheoryReference = __assign(__assign(__assign(__assign(__assign(__assig
|
|
|
30668
31057
|
'12 nth:lcm 8',
|
|
30669
31058
|
'nth:lcm(100, 25)',
|
|
30670
31059
|
'nth:lcm(37, 1)',
|
|
30671
|
-
'nth:lcm(0, 0)',
|
|
30672
31060
|
'nth:lcm(0, 5)',
|
|
30673
31061
|
'nth:lcm(5, 0)',
|
|
30674
31062
|
],
|