squint-cljs 0.4.67 → 0.4.69
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/README.md +5 -2
- package/index.js +1 -1
- package/lib/cli.js +44 -44
- package/lib/cljs.pprint.js +192 -192
- package/lib/compiler.js +825 -819
- package/lib/compiler.node.js +25 -30
- package/lib/compiler.sci.js +1098 -1099
- package/lib/node.nrepl_server.js +15 -15
- package/lib/squint.core.umd.js +1 -1
- package/package.json +2 -1
- package/src/squint/core.js +121 -113
package/src/squint/core.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "^_", "argsIgnorePattern": "^_", "destructuredArrayIgnorePattern": "^_"}]*/
|
|
2
|
+
|
|
1
3
|
function toFn(x) {
|
|
2
4
|
if (x == null) return x;
|
|
3
5
|
if (x instanceof Function) {
|
|
4
6
|
return x;
|
|
5
7
|
}
|
|
6
|
-
|
|
8
|
+
const t = typeof x;
|
|
7
9
|
if (t === 'string') {
|
|
8
10
|
return (coll, d) => {
|
|
9
11
|
return get(coll, x, d);
|
|
@@ -82,7 +84,7 @@ export function assoc(o, k, v, ...kvs) {
|
|
|
82
84
|
if (!o) {
|
|
83
85
|
o = {};
|
|
84
86
|
}
|
|
85
|
-
|
|
87
|
+
const ret = copy(o);
|
|
86
88
|
assoc_BANG_(ret, k, v, ...kvs);
|
|
87
89
|
return ret;
|
|
88
90
|
}
|
|
@@ -140,7 +142,7 @@ function typeConst(obj) {
|
|
|
140
142
|
}
|
|
141
143
|
|
|
142
144
|
function assoc_in_with(f, fname, o, keys, value) {
|
|
143
|
-
|
|
145
|
+
const baseType = typeConst(o);
|
|
144
146
|
if (baseType !== MAP_TYPE && baseType !== ARRAY_TYPE && baseType !== OBJECT_TYPE)
|
|
145
147
|
throw new Error(
|
|
146
148
|
`Illegal argument: ${fname} expects the first argument to be a Map, Array, or Object.`
|
|
@@ -150,7 +152,7 @@ function assoc_in_with(f, fname, o, keys, value) {
|
|
|
150
152
|
let lastInChain = o;
|
|
151
153
|
|
|
152
154
|
for (let i = 0; i < keys.length - 1; i += 1) {
|
|
153
|
-
|
|
155
|
+
const k = keys[i];
|
|
154
156
|
let chainValue;
|
|
155
157
|
if (lastInChain instanceof Map) chainValue = lastInChain.get(k);
|
|
156
158
|
else chainValue = lastInChain[k];
|
|
@@ -176,7 +178,7 @@ export function assoc_in(o, keys, value) {
|
|
|
176
178
|
|
|
177
179
|
export function assoc_in_BANG_(o, keys, value) {
|
|
178
180
|
var currObj = o;
|
|
179
|
-
|
|
181
|
+
const baseType = typeConst(o);
|
|
180
182
|
for (const k of keys.splice(0, keys.length - 1)) {
|
|
181
183
|
let v = get(currObj, k);
|
|
182
184
|
if (v === undefined) {
|
|
@@ -196,7 +198,7 @@ export function comp(...fs) {
|
|
|
196
198
|
} else if (fs.length === 1) {
|
|
197
199
|
return fs[0];
|
|
198
200
|
}
|
|
199
|
-
|
|
201
|
+
const [f, ...more] = fs.slice().reverse();
|
|
200
202
|
return function (...args) {
|
|
201
203
|
let x = f(...args);
|
|
202
204
|
for (const g of more) {
|
|
@@ -211,8 +213,9 @@ export function conj_BANG_(...xs) {
|
|
|
211
213
|
return vector();
|
|
212
214
|
}
|
|
213
215
|
|
|
214
|
-
|
|
216
|
+
const [_o, ...rest] = xs;
|
|
215
217
|
|
|
218
|
+
let o = _o;
|
|
216
219
|
if (o === null || o === undefined) {
|
|
217
220
|
o = [];
|
|
218
221
|
}
|
|
@@ -258,11 +261,13 @@ export function conj(...xs) {
|
|
|
258
261
|
return vector();
|
|
259
262
|
}
|
|
260
263
|
|
|
261
|
-
|
|
264
|
+
const [_o, ...rest] = xs;
|
|
262
265
|
|
|
266
|
+
let o = _o;
|
|
263
267
|
if (o === null || o === undefined) {
|
|
264
268
|
o = [];
|
|
265
269
|
}
|
|
270
|
+
let m, o2;
|
|
266
271
|
|
|
267
272
|
switch (typeConst(o)) {
|
|
268
273
|
case SET_TYPE:
|
|
@@ -272,8 +277,7 @@ export function conj(...xs) {
|
|
|
272
277
|
case ARRAY_TYPE:
|
|
273
278
|
return [...o, ...rest];
|
|
274
279
|
case MAP_TYPE:
|
|
275
|
-
|
|
276
|
-
|
|
280
|
+
m = new Map(o);
|
|
277
281
|
for (const x of rest) {
|
|
278
282
|
if (!Array.isArray(x))
|
|
279
283
|
iterable(x).forEach((kv) => {
|
|
@@ -289,7 +293,7 @@ export function conj(...xs) {
|
|
|
289
293
|
yield* o;
|
|
290
294
|
});
|
|
291
295
|
case OBJECT_TYPE:
|
|
292
|
-
|
|
296
|
+
o2 = { ...o };
|
|
293
297
|
|
|
294
298
|
for (const x of rest) {
|
|
295
299
|
if (!Array.isArray(x)) Object.assign(o2, x);
|
|
@@ -312,7 +316,7 @@ export function disj_BANG_(s, ...xs) {
|
|
|
312
316
|
}
|
|
313
317
|
|
|
314
318
|
export function disj(s, ...xs) {
|
|
315
|
-
|
|
319
|
+
const s1 = new Set([...s]);
|
|
316
320
|
return disj_BANG_(s1, ...xs);
|
|
317
321
|
}
|
|
318
322
|
|
|
@@ -337,7 +341,7 @@ export function dissoc_BANG_(m, ...ks) {
|
|
|
337
341
|
}
|
|
338
342
|
|
|
339
343
|
export function dissoc(m, ...ks) {
|
|
340
|
-
|
|
344
|
+
const m2 = { ...m };
|
|
341
345
|
|
|
342
346
|
for (const k of ks) {
|
|
343
347
|
delete m2[k];
|
|
@@ -364,9 +368,9 @@ export function nth(coll, idx, orElse) {
|
|
|
364
368
|
if (Array.isArray(coll)) {
|
|
365
369
|
elt = coll[idx];
|
|
366
370
|
} else {
|
|
367
|
-
|
|
371
|
+
const iter = iterable(coll);
|
|
368
372
|
let i = 0;
|
|
369
|
-
for (
|
|
373
|
+
for (const value of iter) {
|
|
370
374
|
if (i++ == idx) {
|
|
371
375
|
elt = value;
|
|
372
376
|
break;
|
|
@@ -394,6 +398,7 @@ export function get(coll, key, otherwise = undefined) {
|
|
|
394
398
|
return v;
|
|
395
399
|
}
|
|
396
400
|
}
|
|
401
|
+
let g;
|
|
397
402
|
switch (typeConst(coll)) {
|
|
398
403
|
case SET_TYPE:
|
|
399
404
|
if (coll.has(key)) v = key;
|
|
@@ -406,12 +411,14 @@ export function get(coll, key, otherwise = undefined) {
|
|
|
406
411
|
break;
|
|
407
412
|
default:
|
|
408
413
|
// we choose .get as the default implementation, e.g. fetch Headers are not Maps, but do implement a .get method
|
|
409
|
-
|
|
414
|
+
g = coll['get'];
|
|
410
415
|
if (g instanceof Function) {
|
|
411
416
|
try {
|
|
412
417
|
v = coll.get(key);
|
|
413
418
|
break;
|
|
414
|
-
} catch (e) {
|
|
419
|
+
} catch (e) {
|
|
420
|
+
// ignore error
|
|
421
|
+
}
|
|
415
422
|
}
|
|
416
423
|
v = coll[key];
|
|
417
424
|
break;
|
|
@@ -453,24 +460,24 @@ export const es6_iterator = _iterator;
|
|
|
453
460
|
|
|
454
461
|
export function seq(x) {
|
|
455
462
|
if (x == null) return x;
|
|
456
|
-
|
|
463
|
+
const iter = iterable(x);
|
|
457
464
|
// return nil for terminal checking
|
|
458
465
|
if (iter.length === 0 || iter.size === 0) {
|
|
459
466
|
return null;
|
|
460
467
|
}
|
|
461
|
-
|
|
468
|
+
const _i = iter[Symbol.iterator]();
|
|
462
469
|
if (_i.next().done) return null;
|
|
463
470
|
return iter;
|
|
464
471
|
}
|
|
465
472
|
|
|
466
473
|
export function first(coll) {
|
|
467
474
|
// destructuring uses iterable protocol
|
|
468
|
-
|
|
475
|
+
const [first] = iterable(coll);
|
|
469
476
|
return first;
|
|
470
477
|
}
|
|
471
478
|
|
|
472
479
|
export function second(coll) {
|
|
473
|
-
|
|
480
|
+
const [_, v] = iterable(coll);
|
|
474
481
|
return v;
|
|
475
482
|
}
|
|
476
483
|
|
|
@@ -500,11 +507,11 @@ class Reduced {
|
|
|
500
507
|
|
|
501
508
|
export function last(coll) {
|
|
502
509
|
coll = iterable(coll);
|
|
510
|
+
let lastEl;
|
|
503
511
|
switch (typeConst(coll)) {
|
|
504
512
|
case ARRAY_TYPE:
|
|
505
513
|
return coll[coll.length - 1];
|
|
506
514
|
default:
|
|
507
|
-
let lastEl;
|
|
508
515
|
for (const x of coll) {
|
|
509
516
|
lastEl = x;
|
|
510
517
|
}
|
|
@@ -525,7 +532,7 @@ export function reduce(f, arg1, arg2) {
|
|
|
525
532
|
let coll, val;
|
|
526
533
|
if (arg2 === undefined) {
|
|
527
534
|
// (reduce f coll)
|
|
528
|
-
|
|
535
|
+
const iter = iterable(arg1)[Symbol.iterator]();
|
|
529
536
|
val = iter.next().value;
|
|
530
537
|
coll = iter;
|
|
531
538
|
} else {
|
|
@@ -629,7 +636,7 @@ export function map(f, ...colls) {
|
|
|
629
636
|
return lazy(function* () {
|
|
630
637
|
const iters = colls.map((coll) => es6_iterator(iterable(coll)));
|
|
631
638
|
while (true) {
|
|
632
|
-
|
|
639
|
+
const args = [];
|
|
633
640
|
for (const i of iters) {
|
|
634
641
|
const nextVal = i.next();
|
|
635
642
|
if (nextVal.done) {
|
|
@@ -664,7 +671,7 @@ export function remove(pred, coll) {
|
|
|
664
671
|
|
|
665
672
|
export function map_indexed(f, coll) {
|
|
666
673
|
f = toFn(f);
|
|
667
|
-
|
|
674
|
+
const ret = [];
|
|
668
675
|
let i = 0;
|
|
669
676
|
for (const x of iterable(coll)) {
|
|
670
677
|
ret.push(f(i, x));
|
|
@@ -675,10 +682,10 @@ export function map_indexed(f, coll) {
|
|
|
675
682
|
|
|
676
683
|
export function keep_indexed(f, coll) {
|
|
677
684
|
f = toFn(f);
|
|
678
|
-
|
|
685
|
+
const ret = [];
|
|
679
686
|
let i = 0;
|
|
680
687
|
for (const x of iterable(coll)) {
|
|
681
|
-
|
|
688
|
+
const fret = f(i, x);
|
|
682
689
|
if (truth_(fret)) {
|
|
683
690
|
ret.push(fret);
|
|
684
691
|
}
|
|
@@ -734,12 +741,12 @@ export function Atom(init) {
|
|
|
734
741
|
this._deref = () => this.val;
|
|
735
742
|
this._hasWatches = false;
|
|
736
743
|
this._reset_BANG_ = (x) => {
|
|
737
|
-
|
|
744
|
+
const old_val = this.val;
|
|
738
745
|
this.val = x;
|
|
739
746
|
if (this._hasWatches) {
|
|
740
|
-
for (
|
|
741
|
-
|
|
742
|
-
|
|
747
|
+
for (const entry of Object.entries(this._watches)) {
|
|
748
|
+
const k = entry[0];
|
|
749
|
+
const f = entry[1];
|
|
743
750
|
f(k, this, old_val, x);
|
|
744
751
|
}
|
|
745
752
|
}
|
|
@@ -792,7 +799,7 @@ export function range(begin, end, step) {
|
|
|
792
799
|
}
|
|
793
800
|
|
|
794
801
|
export function re_matches(re, s) {
|
|
795
|
-
|
|
802
|
+
const matches = re.exec(s);
|
|
796
803
|
if (matches && s === matches[0]) {
|
|
797
804
|
if (matches.length === 1) {
|
|
798
805
|
return matches[0];
|
|
@@ -805,7 +812,7 @@ export function re_matches(re, s) {
|
|
|
805
812
|
|
|
806
813
|
export function re_find(re, s) {
|
|
807
814
|
if (string_QMARK_(s)) {
|
|
808
|
-
|
|
815
|
+
const matches = re.exec(s);
|
|
809
816
|
if (matches != null) {
|
|
810
817
|
if (matches.length === 1) return matches[0];
|
|
811
818
|
else {
|
|
@@ -852,7 +859,7 @@ export function apply(f, ...args) {
|
|
|
852
859
|
f = toFn(f);
|
|
853
860
|
const xs = args.slice(0, args.length - 1);
|
|
854
861
|
const coll = iterable(args[args.length - 1]);
|
|
855
|
-
|
|
862
|
+
const af = f[IApply__apply];
|
|
856
863
|
if (af) {
|
|
857
864
|
return af(...xs, coll);
|
|
858
865
|
}
|
|
@@ -913,7 +920,7 @@ concat[IApply__apply] = (colls) => {
|
|
|
913
920
|
};
|
|
914
921
|
|
|
915
922
|
export function mapcat(f, ...colls) {
|
|
916
|
-
|
|
923
|
+
const mapped = map(f, ...colls);
|
|
917
924
|
return concat1(mapped);
|
|
918
925
|
}
|
|
919
926
|
|
|
@@ -925,7 +932,7 @@ export function interleave(...colls) {
|
|
|
925
932
|
return lazy(function* () {
|
|
926
933
|
const iters = colls.map((coll) => es6_iterator(iterable(coll)));
|
|
927
934
|
while (true) {
|
|
928
|
-
|
|
935
|
+
const res = [];
|
|
929
936
|
for (const i of iters) {
|
|
930
937
|
const nextVal = i.next();
|
|
931
938
|
if (nextVal.done) {
|
|
@@ -982,7 +989,7 @@ function partitionInternal(n, step, pad, coll, all) {
|
|
|
982
989
|
return lazy(function* () {
|
|
983
990
|
let p = [];
|
|
984
991
|
let i = 0;
|
|
985
|
-
for (
|
|
992
|
+
for (const x of iterable(coll)) {
|
|
986
993
|
if (i < n) {
|
|
987
994
|
p.push(x);
|
|
988
995
|
if (p.length === n) {
|
|
@@ -1010,23 +1017,23 @@ function partitionInternal(n, step, pad, coll, all) {
|
|
|
1010
1017
|
export function partition_by(f, coll) {
|
|
1011
1018
|
f = toFn(f);
|
|
1012
1019
|
return lazy(function* () {
|
|
1013
|
-
|
|
1014
|
-
|
|
1020
|
+
const iter = es6_iterator(coll);
|
|
1021
|
+
const _fst = iter.next();
|
|
1015
1022
|
if (_fst.done) {
|
|
1016
1023
|
yield* null;
|
|
1017
1024
|
}
|
|
1018
|
-
|
|
1025
|
+
const fst = _fst.value;
|
|
1019
1026
|
let fv = f(fst);
|
|
1020
1027
|
let run = [fst];
|
|
1021
1028
|
let rst = [];
|
|
1022
1029
|
while (true) {
|
|
1023
|
-
|
|
1030
|
+
const next = iter.next();
|
|
1024
1031
|
if (next.done) {
|
|
1025
1032
|
yield run;
|
|
1026
1033
|
break;
|
|
1027
1034
|
}
|
|
1028
|
-
|
|
1029
|
-
|
|
1035
|
+
const _v = next.value;
|
|
1036
|
+
const _fv = f(_v);
|
|
1030
1037
|
if (fv == _fv) {
|
|
1031
1038
|
run.push(_v);
|
|
1032
1039
|
} else {
|
|
@@ -1079,16 +1086,16 @@ export function merge_with(f, ...maps) {
|
|
|
1079
1086
|
}
|
|
1080
1087
|
}
|
|
1081
1088
|
if (hasMap) {
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1089
|
+
const mergeEntry = (m, e) => {
|
|
1090
|
+
const k = key(e);
|
|
1091
|
+
const v = val(e);
|
|
1085
1092
|
if (contains_QMARK_(m, k)) {
|
|
1086
1093
|
return assoc(m, k, f(get(m, k), v));
|
|
1087
1094
|
} else {
|
|
1088
1095
|
return assoc(m, k, v);
|
|
1089
1096
|
}
|
|
1090
1097
|
};
|
|
1091
|
-
|
|
1098
|
+
const merge2 = (m1, m2) => {
|
|
1092
1099
|
return reduce(mergeEntry, m1 || {}, seq(m2));
|
|
1093
1100
|
};
|
|
1094
1101
|
return reduce(merge2, maps);
|
|
@@ -1102,24 +1109,25 @@ export function system_time() {
|
|
|
1102
1109
|
}
|
|
1103
1110
|
|
|
1104
1111
|
export function into(...args) {
|
|
1112
|
+
let to, xform, from, c, rf;
|
|
1105
1113
|
switch (args.length) {
|
|
1106
1114
|
case 0:
|
|
1107
1115
|
return [];
|
|
1108
1116
|
case 1:
|
|
1109
1117
|
return args[0];
|
|
1110
1118
|
case 2:
|
|
1111
|
-
return conj(args[0] ?? [], ...iterable(args[1]))
|
|
1119
|
+
return conj(args[0] ?? [], ...iterable(args[1]));
|
|
1112
1120
|
case 3:
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1121
|
+
to = args[0];
|
|
1122
|
+
xform = args[1];
|
|
1123
|
+
from = args[2];
|
|
1124
|
+
c = copy(to);
|
|
1125
|
+
rf = (coll, v) => {
|
|
1118
1126
|
if (v === undefined) {
|
|
1119
|
-
return coll
|
|
1127
|
+
return coll;
|
|
1120
1128
|
}
|
|
1121
1129
|
return conj_BANG_(coll, v);
|
|
1122
|
-
}
|
|
1130
|
+
};
|
|
1123
1131
|
return transduce(xform, rf, c, from);
|
|
1124
1132
|
default:
|
|
1125
1133
|
throw TypeError(`Invalid arity call of into: ${args.length}`);
|
|
@@ -1140,11 +1148,11 @@ export function repeat(...args) {
|
|
|
1140
1148
|
[IIterable__iterator]:
|
|
1141
1149
|
args.length == 1
|
|
1142
1150
|
? function* () {
|
|
1143
|
-
|
|
1151
|
+
const x = args[0];
|
|
1144
1152
|
while (true) yield x;
|
|
1145
1153
|
}
|
|
1146
1154
|
: function* () {
|
|
1147
|
-
|
|
1155
|
+
const [n, x] = args;
|
|
1148
1156
|
for (var i = 0; i < n; i++) yield x;
|
|
1149
1157
|
},
|
|
1150
1158
|
};
|
|
@@ -1181,7 +1189,7 @@ export function take_nth(n, coll) {
|
|
|
1181
1189
|
|
|
1182
1190
|
return lazy(function* () {
|
|
1183
1191
|
let i = 0;
|
|
1184
|
-
for (
|
|
1192
|
+
for (const x of iterable(coll)) {
|
|
1185
1193
|
if (i % n === 0) {
|
|
1186
1194
|
yield x;
|
|
1187
1195
|
}
|
|
@@ -1205,7 +1213,7 @@ export function cycle(coll) {
|
|
|
1205
1213
|
|
|
1206
1214
|
export function drop(n, xs) {
|
|
1207
1215
|
return lazy(function* () {
|
|
1208
|
-
|
|
1216
|
+
const iter = _iterator(iterable(xs));
|
|
1209
1217
|
for (let x = 0; x < n; x++) {
|
|
1210
1218
|
iter.next();
|
|
1211
1219
|
}
|
|
@@ -1216,13 +1224,13 @@ export function drop(n, xs) {
|
|
|
1216
1224
|
export function drop_while(pred, xs) {
|
|
1217
1225
|
pred = toFn(pred);
|
|
1218
1226
|
return lazy(function* () {
|
|
1219
|
-
|
|
1227
|
+
const iter = _iterator(iterable(xs));
|
|
1220
1228
|
while (true) {
|
|
1221
|
-
|
|
1229
|
+
const nextItem = iter.next();
|
|
1222
1230
|
if (nextItem.done) {
|
|
1223
1231
|
break;
|
|
1224
1232
|
}
|
|
1225
|
-
|
|
1233
|
+
const value = nextItem.value;
|
|
1226
1234
|
if (!truth_(pred(value))) {
|
|
1227
1235
|
yield value;
|
|
1228
1236
|
break;
|
|
@@ -1234,7 +1242,7 @@ export function drop_while(pred, xs) {
|
|
|
1234
1242
|
|
|
1235
1243
|
export function distinct(coll) {
|
|
1236
1244
|
return lazy(function* () {
|
|
1237
|
-
|
|
1245
|
+
const seen = new Set();
|
|
1238
1246
|
for (const x of iterable(coll)) {
|
|
1239
1247
|
if (!seen.has(x)) yield x;
|
|
1240
1248
|
seen.add(x);
|
|
@@ -1275,7 +1283,7 @@ export function fnil(f, x, ...xs) {
|
|
|
1275
1283
|
|
|
1276
1284
|
export function every_QMARK_(pred, coll) {
|
|
1277
1285
|
pred = toFn(pred);
|
|
1278
|
-
for (
|
|
1286
|
+
for (const x of iterable(coll)) {
|
|
1279
1287
|
if (!pred(x)) return false;
|
|
1280
1288
|
}
|
|
1281
1289
|
return true;
|
|
@@ -1308,7 +1316,7 @@ export function sort(f, coll) {
|
|
|
1308
1316
|
f = toFn(f);
|
|
1309
1317
|
coll = iterable(coll);
|
|
1310
1318
|
// we need to clone coll since .sort works in place and .toSorted isn't available on Node < 20
|
|
1311
|
-
|
|
1319
|
+
const clone = [...coll];
|
|
1312
1320
|
// result is guaranteed to be stable since ES2019, like CLJS
|
|
1313
1321
|
return clone.sort(f || compare);
|
|
1314
1322
|
}
|
|
@@ -1318,7 +1326,7 @@ function fnToComparator(f) {
|
|
|
1318
1326
|
return f;
|
|
1319
1327
|
}
|
|
1320
1328
|
return (x, y) => {
|
|
1321
|
-
|
|
1329
|
+
const r = f(x, y);
|
|
1322
1330
|
if (number_QMARK_(r)) {
|
|
1323
1331
|
return r;
|
|
1324
1332
|
}
|
|
@@ -1340,15 +1348,15 @@ export function sort_by(keyfn, comp, coll) {
|
|
|
1340
1348
|
keyfn = toFn(keyfn);
|
|
1341
1349
|
comp = toFn(comp);
|
|
1342
1350
|
return sort((x, y) => {
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1351
|
+
const f = fnToComparator(comp);
|
|
1352
|
+
const kx = keyfn(x);
|
|
1353
|
+
const ky = keyfn(y);
|
|
1346
1354
|
return f(kx, ky);
|
|
1347
1355
|
}, coll);
|
|
1348
1356
|
}
|
|
1349
1357
|
|
|
1350
1358
|
export function shuffle(coll) {
|
|
1351
|
-
return [...coll].sort(function (
|
|
1359
|
+
return [...coll].sort(function (_a, _b) {
|
|
1352
1360
|
return Math.random() - 0.5;
|
|
1353
1361
|
});
|
|
1354
1362
|
}
|
|
@@ -1368,7 +1376,7 @@ export function not_any_QMARK_(pred, coll) {
|
|
|
1368
1376
|
}
|
|
1369
1377
|
|
|
1370
1378
|
export function replace(smap, coll) {
|
|
1371
|
-
|
|
1379
|
+
const mapf = Array.isArray(coll) ? mapv : map;
|
|
1372
1380
|
return mapf((x) => {
|
|
1373
1381
|
const repl = smap[x];
|
|
1374
1382
|
if (repl !== undefined) {
|
|
@@ -1388,7 +1396,7 @@ export function rand_int(n) {
|
|
|
1388
1396
|
}
|
|
1389
1397
|
|
|
1390
1398
|
export function rand_nth(coll) {
|
|
1391
|
-
|
|
1399
|
+
const ri = rand_int(count(coll));
|
|
1392
1400
|
return nth(coll, ri);
|
|
1393
1401
|
}
|
|
1394
1402
|
|
|
@@ -1449,13 +1457,13 @@ export class LazySeq {
|
|
|
1449
1457
|
}
|
|
1450
1458
|
|
|
1451
1459
|
export function butlast(coll) {
|
|
1452
|
-
|
|
1460
|
+
const x = [...iterable(coll)];
|
|
1453
1461
|
x.pop();
|
|
1454
1462
|
return x.length > 0 ? x : null;
|
|
1455
1463
|
}
|
|
1456
1464
|
|
|
1457
1465
|
export function drop_last(...args) {
|
|
1458
|
-
|
|
1466
|
+
const [n, coll] = args.length > 1 ? args : [1, args[0]];
|
|
1459
1467
|
return map((x, _) => x, coll, drop(n, coll));
|
|
1460
1468
|
}
|
|
1461
1469
|
|
|
@@ -1474,7 +1482,7 @@ export function count(coll) {
|
|
|
1474
1482
|
return len;
|
|
1475
1483
|
}
|
|
1476
1484
|
let ret = 0;
|
|
1477
|
-
for (const
|
|
1485
|
+
for (const _ of iterable(coll)) {
|
|
1478
1486
|
ret++;
|
|
1479
1487
|
}
|
|
1480
1488
|
return ret;
|
|
@@ -1509,9 +1517,9 @@ export function pos_QMARK_(x) {
|
|
|
1509
1517
|
}
|
|
1510
1518
|
|
|
1511
1519
|
export function js_obj(...args) {
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1520
|
+
let ctr = 0;
|
|
1521
|
+
const ret = {};
|
|
1522
|
+
for (;;) {
|
|
1515
1523
|
if (ctr >= args.length) {
|
|
1516
1524
|
break;
|
|
1517
1525
|
}
|
|
@@ -1530,11 +1538,11 @@ export function aset(arr, idx, val, ...more) {
|
|
|
1530
1538
|
arr[idx] = val;
|
|
1531
1539
|
return val;
|
|
1532
1540
|
} else {
|
|
1533
|
-
|
|
1534
|
-
|
|
1541
|
+
const path = [idx, val, ...more];
|
|
1542
|
+
const _val = path[path.length - 1];
|
|
1535
1543
|
let innerArray = arr;
|
|
1536
1544
|
let _idx = 0;
|
|
1537
|
-
|
|
1545
|
+
const _pathLen = path.length - 2;
|
|
1538
1546
|
for (; _idx < _pathLen; _idx++) {
|
|
1539
1547
|
innerArray = innerArray[path[_idx]];
|
|
1540
1548
|
}
|
|
@@ -1544,7 +1552,7 @@ export function aset(arr, idx, val, ...more) {
|
|
|
1544
1552
|
}
|
|
1545
1553
|
|
|
1546
1554
|
export function dorun(x) {
|
|
1547
|
-
for (const
|
|
1555
|
+
for (const _ of iterable(x)) {
|
|
1548
1556
|
// nothing here, just consume for side effects
|
|
1549
1557
|
}
|
|
1550
1558
|
return null;
|
|
@@ -1556,7 +1564,7 @@ export function doall(x) {
|
|
|
1556
1564
|
}
|
|
1557
1565
|
|
|
1558
1566
|
export function aclone(arr) {
|
|
1559
|
-
|
|
1567
|
+
const cloned = [...arr];
|
|
1560
1568
|
return cloned;
|
|
1561
1569
|
}
|
|
1562
1570
|
|
|
@@ -1573,7 +1581,7 @@ export function reduce_kv(f, init, m) {
|
|
|
1573
1581
|
return init;
|
|
1574
1582
|
}
|
|
1575
1583
|
var ret = init;
|
|
1576
|
-
for (
|
|
1584
|
+
for (const o of Object.entries(m)) {
|
|
1577
1585
|
ret = f(ret, o[0], o[1]);
|
|
1578
1586
|
}
|
|
1579
1587
|
return ret;
|
|
@@ -1599,9 +1607,9 @@ export function map_QMARK_(x) {
|
|
|
1599
1607
|
|
|
1600
1608
|
export function every_pred(...preds) {
|
|
1601
1609
|
return (...args) => {
|
|
1602
|
-
for (
|
|
1603
|
-
for (
|
|
1604
|
-
|
|
1610
|
+
for (const p of preds) {
|
|
1611
|
+
for (const a of args) {
|
|
1612
|
+
const res = p(a);
|
|
1605
1613
|
if (!res) {
|
|
1606
1614
|
return false;
|
|
1607
1615
|
}
|
|
@@ -1613,10 +1621,10 @@ export function every_pred(...preds) {
|
|
|
1613
1621
|
|
|
1614
1622
|
export function some_fn(...fns) {
|
|
1615
1623
|
return (...args) => {
|
|
1616
|
-
for (
|
|
1617
|
-
for (
|
|
1618
|
-
|
|
1619
|
-
if (
|
|
1624
|
+
for (const f of fns) {
|
|
1625
|
+
for (const a of args) {
|
|
1626
|
+
const res = f(a);
|
|
1627
|
+
if (res) {
|
|
1620
1628
|
return res;
|
|
1621
1629
|
}
|
|
1622
1630
|
}
|
|
@@ -1626,7 +1634,7 @@ export function some_fn(...fns) {
|
|
|
1626
1634
|
}
|
|
1627
1635
|
|
|
1628
1636
|
export function into_array(type, aseq) {
|
|
1629
|
-
|
|
1637
|
+
const theSeq = aseq || type;
|
|
1630
1638
|
return vec(theSeq);
|
|
1631
1639
|
}
|
|
1632
1640
|
|
|
@@ -1643,8 +1651,8 @@ export function iterate(f, x) {
|
|
|
1643
1651
|
export function juxt(...fs) {
|
|
1644
1652
|
fs = fs.map(toFn);
|
|
1645
1653
|
return (...args) => {
|
|
1646
|
-
|
|
1647
|
-
for (
|
|
1654
|
+
const ret = [];
|
|
1655
|
+
for (const f of fs) {
|
|
1648
1656
|
ret.push(f(...args));
|
|
1649
1657
|
}
|
|
1650
1658
|
return ret;
|
|
@@ -1653,7 +1661,7 @@ export function juxt(...fs) {
|
|
|
1653
1661
|
|
|
1654
1662
|
export function next(x) {
|
|
1655
1663
|
if (Array.isArray(x)) {
|
|
1656
|
-
|
|
1664
|
+
const ret = x.slice(1);
|
|
1657
1665
|
if (ret.length > 0) {
|
|
1658
1666
|
return ret;
|
|
1659
1667
|
} else {
|
|
@@ -1674,8 +1682,8 @@ export function compare(x, y) {
|
|
|
1674
1682
|
if (y == null) {
|
|
1675
1683
|
return 1;
|
|
1676
1684
|
}
|
|
1677
|
-
|
|
1678
|
-
|
|
1685
|
+
const tx = typeof(x);
|
|
1686
|
+
const ty = typeof(y);
|
|
1679
1687
|
if (tx === 'number' && ty === 'number' || tx === 'string' && ty === 'string') {
|
|
1680
1688
|
if (x === y) {
|
|
1681
1689
|
return 0;
|
|
@@ -1698,7 +1706,7 @@ export function truth_(x) {
|
|
|
1698
1706
|
return x != null && x !== false;
|
|
1699
1707
|
}
|
|
1700
1708
|
|
|
1701
|
-
export const t = truth_ // backward compat, remove in 2025
|
|
1709
|
+
export const t = truth_; // backward compat, remove in 2025
|
|
1702
1710
|
|
|
1703
1711
|
export function subs(s, start, end) {
|
|
1704
1712
|
return s.substring(start, end);
|
|
@@ -1709,14 +1717,14 @@ export function fn_QMARK_(x) {
|
|
|
1709
1717
|
}
|
|
1710
1718
|
|
|
1711
1719
|
export function* re_seq(re, s) {
|
|
1712
|
-
|
|
1720
|
+
const matches = re.exec(s);
|
|
1713
1721
|
if (matches) {
|
|
1714
|
-
|
|
1715
|
-
|
|
1722
|
+
const match_str = matches[0];
|
|
1723
|
+
const match_vals = matches.length === 1 ? match_str : vec(matches);
|
|
1716
1724
|
yield* cons(
|
|
1717
1725
|
match_vals,
|
|
1718
1726
|
lazy(function* () {
|
|
1719
|
-
|
|
1727
|
+
const post_idx = matches.index + max(1, match_str.length);
|
|
1720
1728
|
if (post_idx <= s.length) {
|
|
1721
1729
|
yield* re_seq(re, subs(s, post_idx));
|
|
1722
1730
|
}
|
|
@@ -1807,7 +1815,7 @@ export function meta(x) {
|
|
|
1807
1815
|
}
|
|
1808
1816
|
|
|
1809
1817
|
export function with_meta(x, m) {
|
|
1810
|
-
|
|
1818
|
+
const ret = copy(x);
|
|
1811
1819
|
ret[_metaSym] = m;
|
|
1812
1820
|
return ret;
|
|
1813
1821
|
}
|
|
@@ -1817,7 +1825,7 @@ export function boolean_QMARK_(x) {
|
|
|
1817
1825
|
}
|
|
1818
1826
|
|
|
1819
1827
|
export function counted_QMARK_(x) {
|
|
1820
|
-
|
|
1828
|
+
const tc = typeConst(x);
|
|
1821
1829
|
switch (tc) {
|
|
1822
1830
|
case (ARRAY_TYPE, MAP_TYPE, OBJECT_TYPE, LIST_TYPE, SET_TYPE):
|
|
1823
1831
|
return true;
|
|
@@ -1834,7 +1842,7 @@ export function bounded_count(n, coll) {
|
|
|
1834
1842
|
}
|
|
1835
1843
|
|
|
1836
1844
|
export function find(m, k) {
|
|
1837
|
-
|
|
1845
|
+
const v = get(m, k);
|
|
1838
1846
|
if (v !== undefined) {
|
|
1839
1847
|
return [k, v];
|
|
1840
1848
|
}
|
|
@@ -1883,7 +1891,7 @@ function parsing_err(x) {
|
|
|
1883
1891
|
export function parse_long(x) {
|
|
1884
1892
|
if (string_QMARK_(x)) {
|
|
1885
1893
|
if (/^[+-]?\d+$/.test(x)) {
|
|
1886
|
-
|
|
1894
|
+
const i = parseInt(x);
|
|
1887
1895
|
if (Number.MIN_SAFE_INTEGER <= i <= Number.MAX_SAFE_INTEGER) {
|
|
1888
1896
|
return i;
|
|
1889
1897
|
}
|
|
@@ -1897,27 +1905,27 @@ function fix(q) {
|
|
|
1897
1905
|
if (q >= 0) {
|
|
1898
1906
|
return Math.floor(q);
|
|
1899
1907
|
}
|
|
1900
|
-
return Math.ceil(
|
|
1908
|
+
return Math.ceil(q);
|
|
1901
1909
|
}
|
|
1902
1910
|
|
|
1903
1911
|
export function quot(n, d) {
|
|
1904
|
-
|
|
1912
|
+
const rem = n % d;
|
|
1905
1913
|
return fix((n - rem) / d);
|
|
1906
1914
|
}
|
|
1907
1915
|
|
|
1908
1916
|
export function transduce(xform, ...args) {
|
|
1909
1917
|
switch (args.length) {
|
|
1910
1918
|
case 2: {
|
|
1911
|
-
|
|
1912
|
-
|
|
1919
|
+
const f = args[0];
|
|
1920
|
+
const coll = args[1];
|
|
1913
1921
|
return transduce(xform, f, f(), coll);
|
|
1914
1922
|
}
|
|
1915
1923
|
default: {
|
|
1916
1924
|
let f = args[0];
|
|
1917
|
-
|
|
1918
|
-
|
|
1925
|
+
const init = args[1];
|
|
1926
|
+
const coll = args[2];
|
|
1919
1927
|
f = xform(f);
|
|
1920
|
-
|
|
1928
|
+
const ret = reduce(f, init, coll);
|
|
1921
1929
|
return f(ret);
|
|
1922
1930
|
}
|
|
1923
1931
|
}
|