squint-cljs 0.0.14 → 0.1.16
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 +4 -0
- package/lib/cli.js +36 -36
- package/lib/compiler.js +783 -757
- package/lib/compiler.node.js +1214 -1211
- package/package.json +1 -1
- package/src/squint/core.js +65 -4
package/package.json
CHANGED
package/src/squint/core.js
CHANGED
|
@@ -273,7 +273,6 @@ export function contains_QMARK_(coll, v) {
|
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
-
|
|
277
276
|
export function dissoc_BANG_(m, ...ks) {
|
|
278
277
|
for (const k of ks) {
|
|
279
278
|
delete m[k];
|
|
@@ -306,7 +305,19 @@ export function println(...args) {
|
|
|
306
305
|
|
|
307
306
|
export function nth(coll, idx, orElse) {
|
|
308
307
|
if (coll) {
|
|
309
|
-
|
|
308
|
+
var elt = undefined;
|
|
309
|
+
if (coll instanceof Array) {
|
|
310
|
+
elt = coll[idx];
|
|
311
|
+
} else {
|
|
312
|
+
let iter = iterable(coll);
|
|
313
|
+
let i = 0;
|
|
314
|
+
for (let value of iter) {
|
|
315
|
+
if (i++ == idx) {
|
|
316
|
+
elt = value;
|
|
317
|
+
break;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
310
321
|
if (elt !== undefined) {
|
|
311
322
|
return elt;
|
|
312
323
|
}
|
|
@@ -565,8 +576,28 @@ export function prn(...xs) {
|
|
|
565
576
|
|
|
566
577
|
export function Atom(init) {
|
|
567
578
|
this.val = init;
|
|
579
|
+
this._watches = {};
|
|
568
580
|
this._deref = () => this.val;
|
|
569
|
-
this.
|
|
581
|
+
this._hasWatches = false;
|
|
582
|
+
this._reset_BANG_ = (x) => {
|
|
583
|
+
let old_val = this.val;
|
|
584
|
+
this.val = x;
|
|
585
|
+
if (this._hasWatches) {
|
|
586
|
+
for (let entry of Object.entries(this._watches)) {
|
|
587
|
+
let k = entry[0];
|
|
588
|
+
let f = entry[1];
|
|
589
|
+
f(k, this, old_val, x);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
return x;
|
|
593
|
+
};
|
|
594
|
+
this._add_watch = (k, fn) => {
|
|
595
|
+
this._watches[k] = fn;
|
|
596
|
+
this._hasWatches = true;
|
|
597
|
+
};
|
|
598
|
+
this._remove_watch = (k) => {
|
|
599
|
+
delete this._watches[k];
|
|
600
|
+
};
|
|
570
601
|
}
|
|
571
602
|
|
|
572
603
|
export function atom(init) {
|
|
@@ -1028,6 +1059,11 @@ export function rand_int(n) {
|
|
|
1028
1059
|
return Math.floor(Math.random() * n);
|
|
1029
1060
|
}
|
|
1030
1061
|
|
|
1062
|
+
export function rand_nth(coll) {
|
|
1063
|
+
let ri = rand_int(count(coll));
|
|
1064
|
+
return nth(coll, ri);
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1031
1067
|
function _repeatedly(f) {
|
|
1032
1068
|
return lazy(function* () {
|
|
1033
1069
|
while (true) yield f();
|
|
@@ -1146,7 +1182,7 @@ export function js_obj(...args) {
|
|
|
1146
1182
|
if (ctr >= args.length) {
|
|
1147
1183
|
break;
|
|
1148
1184
|
}
|
|
1149
|
-
ret[args[ctr]]=args[ctr+1];
|
|
1185
|
+
ret[args[ctr]] = args[ctr + 1];
|
|
1150
1186
|
ctr = ctr + 2;
|
|
1151
1187
|
}
|
|
1152
1188
|
return ret;
|
|
@@ -1160,3 +1196,28 @@ export function aset(arr, idx, val) {
|
|
|
1160
1196
|
arr[idx] = val;
|
|
1161
1197
|
return val;
|
|
1162
1198
|
}
|
|
1199
|
+
|
|
1200
|
+
export function dorun(x) {
|
|
1201
|
+
for (const o of iterable(x)) {
|
|
1202
|
+
// nothing here, just consume for side effects
|
|
1203
|
+
}
|
|
1204
|
+
return null;
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
export function doall(x) {
|
|
1208
|
+
// realize as concrete array
|
|
1209
|
+
return vec(x);
|
|
1210
|
+
}
|
|
1211
|
+
|
|
1212
|
+
export function aclone(arr) {
|
|
1213
|
+
let cloned = [...arr];
|
|
1214
|
+
return cloned;
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
export function add_watch(ref, key, fn) {
|
|
1218
|
+
return ref._add_watch(key, fn);
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
export function remove_watch(ref, key) {
|
|
1222
|
+
return ref._remove_watch(key);
|
|
1223
|
+
}
|