@calcit/procs 0.6.29 → 0.6.30
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/lib/calcit-data.mjs +6 -3
- package/lib/calcit.procs.mjs +5 -5
- package/lib/custom-formatter.mjs +4 -2
- package/lib/js-cirru.mjs +6 -6
- package/lib/js-list.mjs +20 -20
- package/lib/js-tuple.mjs +20 -19
- package/package.json +1 -1
- package/ts-src/calcit-data.mts +6 -3
- package/ts-src/calcit.procs.mts +5 -5
- package/ts-src/custom-formatter.mts +4 -2
- package/ts-src/js-cirru.mts +6 -6
- package/ts-src/js-list.mts +20 -20
- package/ts-src/js-tuple.mts +21 -19
package/lib/calcit-data.mjs
CHANGED
|
@@ -216,8 +216,11 @@ export let hashFunction = (x) => {
|
|
|
216
216
|
}
|
|
217
217
|
if (x instanceof CalcitTuple) {
|
|
218
218
|
let base = defaultHash_tuple;
|
|
219
|
-
base = mergeValueHash(base, hashFunction(x.
|
|
220
|
-
|
|
219
|
+
base = mergeValueHash(base, hashFunction(x.tag));
|
|
220
|
+
for (let idx = 0; idx < x.extra.length; idx++) {
|
|
221
|
+
let item = x.extra[idx];
|
|
222
|
+
base = mergeValueHash(base, hashFunction(item));
|
|
223
|
+
}
|
|
221
224
|
x.cachedHash = base;
|
|
222
225
|
return base;
|
|
223
226
|
}
|
|
@@ -536,7 +539,7 @@ export let _$n__$e_ = (x, y) => {
|
|
|
536
539
|
}
|
|
537
540
|
if (x instanceof CalcitTuple) {
|
|
538
541
|
if (y instanceof CalcitTuple) {
|
|
539
|
-
return _$n__$e_(x.
|
|
542
|
+
return _$n__$e_(x.tag, y.tag) && _$n__$e_(x.get(1), y.get(1));
|
|
540
543
|
}
|
|
541
544
|
return false;
|
|
542
545
|
}
|
package/lib/calcit.procs.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var _a;
|
|
2
2
|
// CALCIT VERSION
|
|
3
|
-
export const calcit_version = "0.6.
|
|
3
|
+
export const calcit_version = "0.6.30";
|
|
4
4
|
import { parse } from "@cirru/parser.ts";
|
|
5
5
|
import { writeCirruCode } from "@cirru/writer.ts";
|
|
6
6
|
import { CalcitSymbol, CalcitKeyword, CalcitRef, CalcitRecur, kwd, refsRegistry, toString, getStringName, _$n__$e_, hashFunction, } from "./calcit-data.mjs";
|
|
@@ -1161,8 +1161,8 @@ export let _$n_js_object = (...xs) => {
|
|
|
1161
1161
|
}
|
|
1162
1162
|
return ret;
|
|
1163
1163
|
};
|
|
1164
|
-
export let _$o__$o_ = (
|
|
1165
|
-
return new CalcitTuple(
|
|
1164
|
+
export let _$o__$o_ = (tag, ...extra) => {
|
|
1165
|
+
return new CalcitTuple(tag, extra);
|
|
1166
1166
|
};
|
|
1167
1167
|
// mutable place for core to register
|
|
1168
1168
|
let calcit_builtin_classes = {
|
|
@@ -1192,8 +1192,8 @@ export function invoke_method(p, obj, ...args) {
|
|
|
1192
1192
|
klass = calcit_builtin_classes.nil;
|
|
1193
1193
|
}
|
|
1194
1194
|
else if (obj instanceof CalcitTuple) {
|
|
1195
|
-
if (obj.
|
|
1196
|
-
klass = obj.
|
|
1195
|
+
if (obj.tag instanceof CalcitRecord) {
|
|
1196
|
+
klass = obj.tag;
|
|
1197
1197
|
}
|
|
1198
1198
|
else {
|
|
1199
1199
|
throw new Error("Method invoking expected a record as class");
|
package/lib/custom-formatter.mjs
CHANGED
|
@@ -56,8 +56,10 @@ export let load_console_formatter_$x_ = () => {
|
|
|
56
56
|
if (obj instanceof CalcitTuple) {
|
|
57
57
|
let ret = ["div", {}];
|
|
58
58
|
ret.push(["div", { style: "display: inline-block; color: hsl(300, 100%, 40%); " }, "::"]);
|
|
59
|
-
ret.push(["div", { style: "margin-left: 6px; display: inline-block;" }, embedObject(obj.
|
|
60
|
-
|
|
59
|
+
ret.push(["div", { style: "margin-left: 6px; display: inline-block;" }, embedObject(obj.tag)]);
|
|
60
|
+
for (let idx = 0; idx < obj.extra.length; idx++) {
|
|
61
|
+
ret.push(["div", { style: "margin-left: 6px; display: inline-block;" }, embedObject(obj.extra[idx])]);
|
|
62
|
+
}
|
|
61
63
|
return ret;
|
|
62
64
|
}
|
|
63
65
|
if (obj instanceof CalcitRef) {
|
package/lib/js-cirru.mjs
CHANGED
|
@@ -123,15 +123,15 @@ export let to_cirru_edn = (x) => {
|
|
|
123
123
|
return buffer;
|
|
124
124
|
}
|
|
125
125
|
if (x instanceof CalcitTuple) {
|
|
126
|
-
if (x.
|
|
126
|
+
if (x.tag instanceof CalcitSymbol && x.tag.value === "quote") {
|
|
127
127
|
// turn `x.snd` with CalcitList into raw Cirru nodes, which is in plain Array
|
|
128
|
-
return ["quote", toWriterNode(x.
|
|
128
|
+
return ["quote", toWriterNode(x.get(1))];
|
|
129
129
|
}
|
|
130
|
-
else if (x.
|
|
131
|
-
return ["::", x.
|
|
130
|
+
else if (x.tag instanceof CalcitRecord) {
|
|
131
|
+
return ["::", x.tag.name.toString(), to_cirru_edn(x.get(1))];
|
|
132
132
|
}
|
|
133
133
|
else {
|
|
134
|
-
throw new Error(`Unsupported tag for EDN: ${x.
|
|
134
|
+
throw new Error(`Unsupported tag for EDN: ${x.tag}`);
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
console.error(x);
|
|
@@ -248,7 +248,7 @@ export let extract_cirru_edn = (x) => {
|
|
|
248
248
|
if (x.length < 3) {
|
|
249
249
|
throw new Error("tuple expects at least 2 values");
|
|
250
250
|
}
|
|
251
|
-
return new CalcitTuple(extract_cirru_edn(x[1]),
|
|
251
|
+
return new CalcitTuple(extract_cirru_edn(x[1]), x.slice(2).map(extract_cirru_edn));
|
|
252
252
|
}
|
|
253
253
|
}
|
|
254
254
|
console.error(x);
|
package/lib/js-list.mjs
CHANGED
|
@@ -305,12 +305,12 @@ export let foldl_shortcut = function (xs, acc, v0, f) {
|
|
|
305
305
|
let item = xs.get(idx);
|
|
306
306
|
let pair = f(state, item);
|
|
307
307
|
if (pair instanceof CalcitTuple) {
|
|
308
|
-
if (typeof pair.
|
|
309
|
-
if (pair.
|
|
310
|
-
return pair.
|
|
308
|
+
if (typeof pair.tag === "boolean") {
|
|
309
|
+
if (pair.tag) {
|
|
310
|
+
return pair.get(1);
|
|
311
311
|
}
|
|
312
312
|
else {
|
|
313
|
-
state = pair.
|
|
313
|
+
state = pair.get(1);
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
316
|
}
|
|
@@ -327,12 +327,12 @@ export let foldl_shortcut = function (xs, acc, v0, f) {
|
|
|
327
327
|
let item = values[idx];
|
|
328
328
|
let pair = f(state, item);
|
|
329
329
|
if (pair instanceof CalcitTuple) {
|
|
330
|
-
if (typeof pair.
|
|
331
|
-
if (pair.
|
|
332
|
-
return pair.
|
|
330
|
+
if (typeof pair.tag === "boolean") {
|
|
331
|
+
if (pair.tag) {
|
|
332
|
+
return pair.get(1);
|
|
333
333
|
}
|
|
334
334
|
else {
|
|
335
|
-
state = pair.
|
|
335
|
+
state = pair.get(1);
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
338
|
}
|
|
@@ -350,12 +350,12 @@ export let foldl_shortcut = function (xs, acc, v0, f) {
|
|
|
350
350
|
let pos = i << 1;
|
|
351
351
|
let pair = f(state, new CalcitSliceList([xs.chunk[pos], xs.chunk[pos + 1]]));
|
|
352
352
|
if (pair instanceof CalcitTuple) {
|
|
353
|
-
if (typeof pair.
|
|
354
|
-
if (pair.
|
|
355
|
-
return pair.
|
|
353
|
+
if (typeof pair.tag === "boolean") {
|
|
354
|
+
if (pair.tag) {
|
|
355
|
+
return pair.get(1);
|
|
356
356
|
}
|
|
357
357
|
else {
|
|
358
|
-
state = pair.
|
|
358
|
+
state = pair.get(1);
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
361
|
}
|
|
@@ -372,12 +372,12 @@ export let foldl_shortcut = function (xs, acc, v0, f) {
|
|
|
372
372
|
let item = pairs[idx];
|
|
373
373
|
let pair = f(state, new CalcitSliceList(item));
|
|
374
374
|
if (pair instanceof CalcitTuple) {
|
|
375
|
-
if (typeof pair.
|
|
376
|
-
if (pair.
|
|
377
|
-
return pair.
|
|
375
|
+
if (typeof pair.tag === "boolean") {
|
|
376
|
+
if (pair.tag) {
|
|
377
|
+
return pair.get(1);
|
|
378
378
|
}
|
|
379
379
|
else {
|
|
380
|
-
state = pair.
|
|
380
|
+
state = pair.get(1);
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
383
|
}
|
|
@@ -403,12 +403,12 @@ export let foldr_shortcut = function (xs, acc, v0, f) {
|
|
|
403
403
|
let item = xs.get(idx);
|
|
404
404
|
let pair = f(state, item);
|
|
405
405
|
if (pair instanceof CalcitTuple) {
|
|
406
|
-
if (typeof pair.
|
|
407
|
-
if (pair.
|
|
408
|
-
return pair.
|
|
406
|
+
if (typeof pair.tag === "boolean") {
|
|
407
|
+
if (pair.tag) {
|
|
408
|
+
return pair.get(1);
|
|
409
409
|
}
|
|
410
410
|
else {
|
|
411
|
-
state = pair.
|
|
411
|
+
state = pair.get(1);
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
414
|
}
|
package/lib/js-tuple.mjs
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import { toString } from "./calcit-data.mjs";
|
|
2
2
|
export class CalcitTuple {
|
|
3
|
-
constructor(
|
|
4
|
-
this.
|
|
5
|
-
this.snd = b;
|
|
3
|
+
constructor(tag, extra) {
|
|
4
|
+
this.tag = tag;
|
|
6
5
|
this.extra = extra;
|
|
7
6
|
this.cachedHash = null;
|
|
8
7
|
}
|
|
9
8
|
get(n) {
|
|
10
9
|
if (n === 0) {
|
|
11
|
-
return this.
|
|
10
|
+
return this.tag;
|
|
12
11
|
}
|
|
13
|
-
else if (n
|
|
14
|
-
return this.
|
|
15
|
-
}
|
|
16
|
-
else if (n - 2 < this.extra.length) {
|
|
17
|
-
return this.extra[n - 2];
|
|
12
|
+
else if (n - 1 < this.extra.length) {
|
|
13
|
+
return this.extra[n - 1];
|
|
18
14
|
}
|
|
19
15
|
else {
|
|
20
16
|
throw new Error("Tuple only have 2 elements");
|
|
@@ -22,24 +18,29 @@ export class CalcitTuple {
|
|
|
22
18
|
}
|
|
23
19
|
assoc(n, v) {
|
|
24
20
|
if (n === 0) {
|
|
25
|
-
return new CalcitTuple(v, this.
|
|
26
|
-
}
|
|
27
|
-
else if (n === 1) {
|
|
28
|
-
return new CalcitTuple(this.fst, v, this.extra);
|
|
21
|
+
return new CalcitTuple(v, this.extra);
|
|
29
22
|
}
|
|
30
|
-
else if (n -
|
|
23
|
+
else if (n - 1 < this.extra.length) {
|
|
31
24
|
let next_extra = this.extra.slice();
|
|
32
|
-
next_extra[n -
|
|
33
|
-
return new CalcitTuple(this.
|
|
25
|
+
next_extra[n - 1] = v;
|
|
26
|
+
return new CalcitTuple(this.tag, next_extra);
|
|
34
27
|
}
|
|
35
28
|
else {
|
|
36
|
-
throw new Error(
|
|
29
|
+
throw new Error(`Tuple only have ${this.extra.length} elements`);
|
|
37
30
|
}
|
|
38
31
|
}
|
|
39
32
|
count() {
|
|
40
|
-
return
|
|
33
|
+
return 1 + this.extra.length;
|
|
41
34
|
}
|
|
42
35
|
toString(disableJsDataWarning = false) {
|
|
43
|
-
|
|
36
|
+
let args = [this.tag, ...this.extra];
|
|
37
|
+
let content = "";
|
|
38
|
+
for (let i = 0; i < args.length; i++) {
|
|
39
|
+
if (i > 0) {
|
|
40
|
+
content += " ";
|
|
41
|
+
}
|
|
42
|
+
content += toString(args[i], false, disableJsDataWarning);
|
|
43
|
+
}
|
|
44
|
+
return `(&tuple ${content})`;
|
|
44
45
|
}
|
|
45
46
|
}
|
package/package.json
CHANGED
package/ts-src/calcit-data.mts
CHANGED
|
@@ -248,8 +248,11 @@ export let hashFunction = (x: CalcitValue): Hash => {
|
|
|
248
248
|
}
|
|
249
249
|
if (x instanceof CalcitTuple) {
|
|
250
250
|
let base = defaultHash_tuple;
|
|
251
|
-
base = mergeValueHash(base, hashFunction(x.
|
|
252
|
-
|
|
251
|
+
base = mergeValueHash(base, hashFunction(x.tag));
|
|
252
|
+
for (let idx = 0; idx < x.extra.length; idx++) {
|
|
253
|
+
let item = x.extra[idx];
|
|
254
|
+
base = mergeValueHash(base, hashFunction(item));
|
|
255
|
+
}
|
|
253
256
|
x.cachedHash = base;
|
|
254
257
|
return base;
|
|
255
258
|
}
|
|
@@ -578,7 +581,7 @@ export let _$n__$e_ = (x: CalcitValue, y: CalcitValue): boolean => {
|
|
|
578
581
|
}
|
|
579
582
|
if (x instanceof CalcitTuple) {
|
|
580
583
|
if (y instanceof CalcitTuple) {
|
|
581
|
-
return _$n__$e_(x.
|
|
584
|
+
return _$n__$e_(x.tag, y.tag) && _$n__$e_(x.get(1), y.get(1));
|
|
582
585
|
}
|
|
583
586
|
return false;
|
|
584
587
|
}
|
package/ts-src/calcit.procs.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// CALCIT VERSION
|
|
2
|
-
export const calcit_version = "0.6.
|
|
2
|
+
export const calcit_version = "0.6.30";
|
|
3
3
|
|
|
4
4
|
import { parse, ICirruNode } from "@cirru/parser.ts";
|
|
5
5
|
import { writeCirruCode } from "@cirru/writer.ts";
|
|
@@ -1260,8 +1260,8 @@ export let _$n_js_object = (...xs: CalcitValue[]): Record<string, CalcitValue> =
|
|
|
1260
1260
|
return ret;
|
|
1261
1261
|
};
|
|
1262
1262
|
|
|
1263
|
-
export let _$o__$o_ = (
|
|
1264
|
-
return new CalcitTuple(
|
|
1263
|
+
export let _$o__$o_ = (tag: CalcitValue, ...extra: CalcitValue[]): CalcitTuple => {
|
|
1264
|
+
return new CalcitTuple(tag, extra);
|
|
1265
1265
|
};
|
|
1266
1266
|
|
|
1267
1267
|
// mutable place for core to register
|
|
@@ -1294,8 +1294,8 @@ export function invoke_method(p: string, obj: CalcitValue, ...args: CalcitValue[
|
|
|
1294
1294
|
if (obj == null) {
|
|
1295
1295
|
klass = calcit_builtin_classes.nil;
|
|
1296
1296
|
} else if (obj instanceof CalcitTuple) {
|
|
1297
|
-
if (obj.
|
|
1298
|
-
klass = obj.
|
|
1297
|
+
if (obj.tag instanceof CalcitRecord) {
|
|
1298
|
+
klass = obj.tag;
|
|
1299
1299
|
} else {
|
|
1300
1300
|
throw new Error("Method invoking expected a record as class");
|
|
1301
1301
|
}
|
|
@@ -70,8 +70,10 @@ export let load_console_formatter_$x_ = () => {
|
|
|
70
70
|
if (obj instanceof CalcitTuple) {
|
|
71
71
|
let ret: any[] = ["div", {}];
|
|
72
72
|
ret.push(["div", { style: "display: inline-block; color: hsl(300, 100%, 40%); " }, "::"]);
|
|
73
|
-
ret.push(["div", { style: "margin-left: 6px; display: inline-block;" }, embedObject(obj.
|
|
74
|
-
|
|
73
|
+
ret.push(["div", { style: "margin-left: 6px; display: inline-block;" }, embedObject(obj.tag)]);
|
|
74
|
+
for (let idx = 0; idx < obj.extra.length; idx++) {
|
|
75
|
+
ret.push(["div", { style: "margin-left: 6px; display: inline-block;" }, embedObject(obj.extra[idx])]);
|
|
76
|
+
}
|
|
75
77
|
return ret;
|
|
76
78
|
}
|
|
77
79
|
if (obj instanceof CalcitRef) {
|
package/ts-src/js-cirru.mts
CHANGED
|
@@ -126,13 +126,13 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
|
|
|
126
126
|
return buffer;
|
|
127
127
|
}
|
|
128
128
|
if (x instanceof CalcitTuple) {
|
|
129
|
-
if (x.
|
|
129
|
+
if (x.tag instanceof CalcitSymbol && x.tag.value === "quote") {
|
|
130
130
|
// turn `x.snd` with CalcitList into raw Cirru nodes, which is in plain Array
|
|
131
|
-
return ["quote", toWriterNode(x.
|
|
132
|
-
} else if (x.
|
|
133
|
-
return ["::", x.
|
|
131
|
+
return ["quote", toWriterNode(x.get(1) as any)] as CirruEdnFormat;
|
|
132
|
+
} else if (x.tag instanceof CalcitRecord) {
|
|
133
|
+
return ["::", x.tag.name.toString(), to_cirru_edn(x.get(1))];
|
|
134
134
|
} else {
|
|
135
|
-
throw new Error(`Unsupported tag for EDN: ${x.
|
|
135
|
+
throw new Error(`Unsupported tag for EDN: ${x.tag}`);
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
console.error(x);
|
|
@@ -249,7 +249,7 @@ export let extract_cirru_edn = (x: CirruEdnFormat): CalcitValue => {
|
|
|
249
249
|
if (x.length < 3) {
|
|
250
250
|
throw new Error("tuple expects at least 2 values");
|
|
251
251
|
}
|
|
252
|
-
return new CalcitTuple(extract_cirru_edn(x[1]),
|
|
252
|
+
return new CalcitTuple(extract_cirru_edn(x[1]), x.slice(2).map(extract_cirru_edn));
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
255
|
console.error(x);
|
package/ts-src/js-list.mts
CHANGED
|
@@ -325,11 +325,11 @@ export let foldl_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
|
|
|
325
325
|
let item = xs.get(idx);
|
|
326
326
|
let pair = f(state, item);
|
|
327
327
|
if (pair instanceof CalcitTuple) {
|
|
328
|
-
if (typeof pair.
|
|
329
|
-
if (pair.
|
|
330
|
-
return pair.
|
|
328
|
+
if (typeof pair.tag === "boolean") {
|
|
329
|
+
if (pair.tag) {
|
|
330
|
+
return pair.get(1);
|
|
331
331
|
} else {
|
|
332
|
-
state = pair.
|
|
332
|
+
state = pair.get(1);
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
} else {
|
|
@@ -345,11 +345,11 @@ export let foldl_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
|
|
|
345
345
|
let item = values[idx];
|
|
346
346
|
let pair = f(state, item);
|
|
347
347
|
if (pair instanceof CalcitTuple) {
|
|
348
|
-
if (typeof pair.
|
|
349
|
-
if (pair.
|
|
350
|
-
return pair.
|
|
348
|
+
if (typeof pair.tag === "boolean") {
|
|
349
|
+
if (pair.tag) {
|
|
350
|
+
return pair.get(1);
|
|
351
351
|
} else {
|
|
352
|
-
state = pair.
|
|
352
|
+
state = pair.get(1);
|
|
353
353
|
}
|
|
354
354
|
}
|
|
355
355
|
} else {
|
|
@@ -366,11 +366,11 @@ export let foldl_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
|
|
|
366
366
|
let pos = i << 1;
|
|
367
367
|
let pair = f(state, new CalcitSliceList([xs.chunk[pos], xs.chunk[pos + 1]]));
|
|
368
368
|
if (pair instanceof CalcitTuple) {
|
|
369
|
-
if (typeof pair.
|
|
370
|
-
if (pair.
|
|
371
|
-
return pair.
|
|
369
|
+
if (typeof pair.tag === "boolean") {
|
|
370
|
+
if (pair.tag) {
|
|
371
|
+
return pair.get(1);
|
|
372
372
|
} else {
|
|
373
|
-
state = pair.
|
|
373
|
+
state = pair.get(1);
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
376
|
} else {
|
|
@@ -386,11 +386,11 @@ export let foldl_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
|
|
|
386
386
|
let item = pairs[idx];
|
|
387
387
|
let pair = f(state, new CalcitSliceList(item));
|
|
388
388
|
if (pair instanceof CalcitTuple) {
|
|
389
|
-
if (typeof pair.
|
|
390
|
-
if (pair.
|
|
391
|
-
return pair.
|
|
389
|
+
if (typeof pair.tag === "boolean") {
|
|
390
|
+
if (pair.tag) {
|
|
391
|
+
return pair.get(1);
|
|
392
392
|
} else {
|
|
393
|
-
state = pair.
|
|
393
|
+
state = pair.get(1);
|
|
394
394
|
}
|
|
395
395
|
}
|
|
396
396
|
} else {
|
|
@@ -416,11 +416,11 @@ export let foldr_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
|
|
|
416
416
|
let item = xs.get(idx);
|
|
417
417
|
let pair = f(state, item);
|
|
418
418
|
if (pair instanceof CalcitTuple) {
|
|
419
|
-
if (typeof pair.
|
|
420
|
-
if (pair.
|
|
421
|
-
return pair.
|
|
419
|
+
if (typeof pair.tag === "boolean") {
|
|
420
|
+
if (pair.tag) {
|
|
421
|
+
return pair.get(1);
|
|
422
422
|
} else {
|
|
423
|
-
state = pair.
|
|
423
|
+
state = pair.get(1);
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
426
|
} else {
|
package/ts-src/js-tuple.mts
CHANGED
|
@@ -4,44 +4,46 @@ import { CalcitValue } from "./js-primes.mjs";
|
|
|
4
4
|
import { toString } from "./calcit-data.mjs";
|
|
5
5
|
|
|
6
6
|
export class CalcitTuple {
|
|
7
|
-
|
|
8
|
-
snd: CalcitValue;
|
|
7
|
+
tag: CalcitValue;
|
|
9
8
|
extra: CalcitValue[];
|
|
10
9
|
cachedHash: Hash;
|
|
11
|
-
constructor(
|
|
12
|
-
this.
|
|
13
|
-
this.snd = b;
|
|
10
|
+
constructor(tag: CalcitValue, extra: CalcitValue[]) {
|
|
11
|
+
this.tag = tag;
|
|
14
12
|
this.extra = extra;
|
|
15
13
|
this.cachedHash = null;
|
|
16
14
|
}
|
|
17
15
|
get(n: number) {
|
|
18
16
|
if (n === 0) {
|
|
19
|
-
return this.
|
|
20
|
-
} else if (n
|
|
21
|
-
return this.
|
|
22
|
-
} else if (n - 2 < this.extra.length) {
|
|
23
|
-
return this.extra[n - 2];
|
|
17
|
+
return this.tag;
|
|
18
|
+
} else if (n - 1 < this.extra.length) {
|
|
19
|
+
return this.extra[n - 1];
|
|
24
20
|
} else {
|
|
25
21
|
throw new Error("Tuple only have 2 elements");
|
|
26
22
|
}
|
|
27
23
|
}
|
|
28
24
|
assoc(n: number, v: CalcitValue) {
|
|
29
25
|
if (n === 0) {
|
|
30
|
-
return new CalcitTuple(v, this.
|
|
31
|
-
} else if (n
|
|
32
|
-
return new CalcitTuple(this.fst, v, this.extra);
|
|
33
|
-
} else if (n - 2 < this.extra.length) {
|
|
26
|
+
return new CalcitTuple(v, this.extra);
|
|
27
|
+
} else if (n - 1 < this.extra.length) {
|
|
34
28
|
let next_extra = this.extra.slice();
|
|
35
|
-
next_extra[n -
|
|
36
|
-
return new CalcitTuple(this.
|
|
29
|
+
next_extra[n - 1] = v;
|
|
30
|
+
return new CalcitTuple(this.tag, next_extra);
|
|
37
31
|
} else {
|
|
38
|
-
throw new Error(
|
|
32
|
+
throw new Error(`Tuple only have ${this.extra.length} elements`);
|
|
39
33
|
}
|
|
40
34
|
}
|
|
41
35
|
count() {
|
|
42
|
-
return
|
|
36
|
+
return 1 + this.extra.length;
|
|
43
37
|
}
|
|
44
38
|
toString(disableJsDataWarning: boolean = false): string {
|
|
45
|
-
|
|
39
|
+
let args = [this.tag, ...this.extra];
|
|
40
|
+
let content = "";
|
|
41
|
+
for (let i = 0; i < args.length; i++) {
|
|
42
|
+
if (i > 0) {
|
|
43
|
+
content += " ";
|
|
44
|
+
}
|
|
45
|
+
content += toString(args[i], false, disableJsDataWarning);
|
|
46
|
+
}
|
|
47
|
+
return `(&tuple ${content})`;
|
|
46
48
|
}
|
|
47
49
|
}
|