@calcit/procs 0.5.28 → 0.5.31
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 +1 -1
- package/lib/calcit-data.mjs +10 -8
- package/lib/calcit.procs.mjs +2 -101
- package/lib/custom-formatter.mjs +10 -9
- package/lib/js-cirru.mjs +12 -2
- package/lib/js-list.mjs +4 -4
- package/lib/js-map.mjs +8 -8
- package/lib/js-primes.mjs +106 -6
- package/lib/js-record.mjs +2 -2
- package/lib/js-set.mjs +2 -2
- package/lib/js-tuple.mjs +4 -3
- package/package.json +2 -2
- package/ts-src/calcit-data.mts +10 -8
- package/ts-src/calcit.procs.mts +2 -84
- package/ts-src/custom-formatter.mts +10 -9
- package/ts-src/js-cirru.mts +12 -2
- package/ts-src/js-list.mts +4 -4
- package/ts-src/js-map.mts +8 -8
- package/ts-src/js-primes.mts +83 -0
- package/ts-src/js-record.mts +2 -2
- package/ts-src/js-set.mts +2 -2
- package/ts-src/js-tuple.mts +5 -4
- package/.vscode/settings.json +0 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
### Calcit Scripting Language
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Semantically a dialect of ClojureScript. Built with Rust. Compiles to JavaScript ES Modules.
|
|
4
4
|
|
|
5
5
|
- Home http://calcit-lang.org/
|
|
6
6
|
- API Doc http://apis.calcit-lang.org/
|
package/lib/calcit-data.mjs
CHANGED
|
@@ -286,7 +286,7 @@ let hashFunction = (x) => {
|
|
|
286
286
|
};
|
|
287
287
|
// Dirty code to change ternary-tree behavior
|
|
288
288
|
overwriteHashGenerator(hashFunction);
|
|
289
|
-
export let toString = (x, escaped) => {
|
|
289
|
+
export let toString = (x, escaped, disableJsDataWarning = false) => {
|
|
290
290
|
if (x == null) {
|
|
291
291
|
return "nil";
|
|
292
292
|
}
|
|
@@ -320,25 +320,27 @@ export let toString = (x, escaped) => {
|
|
|
320
320
|
return x.toString();
|
|
321
321
|
}
|
|
322
322
|
if (x instanceof CalcitList || x instanceof CalcitSliceList) {
|
|
323
|
-
return x.toString();
|
|
323
|
+
return x.toString(false, disableJsDataWarning);
|
|
324
324
|
}
|
|
325
325
|
if (x instanceof CalcitMap || x instanceof CalcitSliceMap) {
|
|
326
|
-
return x.toString();
|
|
326
|
+
return x.toString(false, disableJsDataWarning);
|
|
327
327
|
}
|
|
328
328
|
if (x instanceof CalcitSet) {
|
|
329
|
-
return x.toString();
|
|
329
|
+
return x.toString(disableJsDataWarning);
|
|
330
330
|
}
|
|
331
331
|
if (x instanceof CalcitRecord) {
|
|
332
|
-
return x.toString();
|
|
332
|
+
return x.toString(disableJsDataWarning);
|
|
333
333
|
}
|
|
334
334
|
if (x instanceof CalcitRef) {
|
|
335
335
|
return x.toString();
|
|
336
336
|
}
|
|
337
337
|
if (x instanceof CalcitTuple) {
|
|
338
|
-
return x.toString();
|
|
338
|
+
return x.toString(disableJsDataWarning);
|
|
339
|
+
}
|
|
340
|
+
if (!disableJsDataWarning) {
|
|
341
|
+
console.warn("Unknown structure to string, better use `console.log`", x);
|
|
339
342
|
}
|
|
340
|
-
|
|
341
|
-
return `${x}`;
|
|
343
|
+
return `(#js ${JSON.stringify(x)})`;
|
|
342
344
|
};
|
|
343
345
|
export let to_js_data = (x, addColon = false) => {
|
|
344
346
|
if (x == null) {
|
package/lib/calcit.procs.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
var _a;
|
|
2
2
|
// CALCIT VERSION
|
|
3
|
-
export const calcit_version = "0.5.
|
|
3
|
+
export const calcit_version = "0.5.31";
|
|
4
4
|
import "@calcit/ternary-tree";
|
|
5
5
|
import { parse } from "@cirru/parser.ts";
|
|
6
6
|
import { writeCirruCode } from "@cirru/writer.ts";
|
|
@@ -16,6 +16,7 @@ export * from "./js-primes.mjs";
|
|
|
16
16
|
export * from "./js-tuple.mjs";
|
|
17
17
|
export * from "./custom-formatter.mjs";
|
|
18
18
|
export * from "./js-cirru.mjs";
|
|
19
|
+
export { _$n_compare } from "./js-primes.mjs";
|
|
19
20
|
import { CalcitList, CalcitSliceList, foldl } from "./js-list.mjs";
|
|
20
21
|
import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
|
|
21
22
|
import { CalcitSet } from "./js-set.mjs";
|
|
@@ -1212,106 +1213,6 @@ export let _$n_map_$o_to_list = (m) => {
|
|
|
1212
1213
|
throw new Error("&map:to-list expected a Map");
|
|
1213
1214
|
}
|
|
1214
1215
|
};
|
|
1215
|
-
var PseudoTypeIndex;
|
|
1216
|
-
(function (PseudoTypeIndex) {
|
|
1217
|
-
PseudoTypeIndex[PseudoTypeIndex["nil"] = 0] = "nil";
|
|
1218
|
-
PseudoTypeIndex[PseudoTypeIndex["bool"] = 1] = "bool";
|
|
1219
|
-
PseudoTypeIndex[PseudoTypeIndex["number"] = 2] = "number";
|
|
1220
|
-
PseudoTypeIndex[PseudoTypeIndex["symbol"] = 3] = "symbol";
|
|
1221
|
-
PseudoTypeIndex[PseudoTypeIndex["keyword"] = 4] = "keyword";
|
|
1222
|
-
PseudoTypeIndex[PseudoTypeIndex["string"] = 5] = "string";
|
|
1223
|
-
PseudoTypeIndex[PseudoTypeIndex["ref"] = 6] = "ref";
|
|
1224
|
-
PseudoTypeIndex[PseudoTypeIndex["tuple"] = 7] = "tuple";
|
|
1225
|
-
PseudoTypeIndex[PseudoTypeIndex["recur"] = 8] = "recur";
|
|
1226
|
-
PseudoTypeIndex[PseudoTypeIndex["list"] = 9] = "list";
|
|
1227
|
-
PseudoTypeIndex[PseudoTypeIndex["set"] = 10] = "set";
|
|
1228
|
-
PseudoTypeIndex[PseudoTypeIndex["map"] = 11] = "map";
|
|
1229
|
-
PseudoTypeIndex[PseudoTypeIndex["record"] = 12] = "record";
|
|
1230
|
-
PseudoTypeIndex[PseudoTypeIndex["fn"] = 13] = "fn";
|
|
1231
|
-
})(PseudoTypeIndex || (PseudoTypeIndex = {}));
|
|
1232
|
-
let typeAsInt = (x) => {
|
|
1233
|
-
// based on order used in Ord traint
|
|
1234
|
-
if (x == null)
|
|
1235
|
-
return PseudoTypeIndex.nil;
|
|
1236
|
-
let t = typeof x;
|
|
1237
|
-
if (t === "boolean")
|
|
1238
|
-
return PseudoTypeIndex.bool;
|
|
1239
|
-
if (t === "number")
|
|
1240
|
-
return PseudoTypeIndex.number;
|
|
1241
|
-
if (x instanceof CalcitSymbol)
|
|
1242
|
-
return PseudoTypeIndex.symbol;
|
|
1243
|
-
if (x instanceof CalcitKeyword)
|
|
1244
|
-
return PseudoTypeIndex.keyword;
|
|
1245
|
-
if (t === "string")
|
|
1246
|
-
return PseudoTypeIndex.string;
|
|
1247
|
-
if (x instanceof CalcitRef)
|
|
1248
|
-
return PseudoTypeIndex.ref;
|
|
1249
|
-
if (x instanceof CalcitTuple)
|
|
1250
|
-
return PseudoTypeIndex.tuple;
|
|
1251
|
-
if (x instanceof CalcitRecur)
|
|
1252
|
-
return PseudoTypeIndex.recur;
|
|
1253
|
-
if (x instanceof CalcitList || x instanceof CalcitSliceList)
|
|
1254
|
-
return PseudoTypeIndex.list;
|
|
1255
|
-
if (x instanceof CalcitSet)
|
|
1256
|
-
return PseudoTypeIndex.set;
|
|
1257
|
-
if (x instanceof CalcitMap || x instanceof CalcitSliceMap)
|
|
1258
|
-
return PseudoTypeIndex.map;
|
|
1259
|
-
if (x instanceof CalcitRecord)
|
|
1260
|
-
return PseudoTypeIndex.record;
|
|
1261
|
-
// proc, fn, macro, syntax, not distinguished
|
|
1262
|
-
if (t === "function")
|
|
1263
|
-
return PseudoTypeIndex.fn;
|
|
1264
|
-
throw new Error("unknown type to compare");
|
|
1265
|
-
};
|
|
1266
|
-
let rawCompare = (x, y) => {
|
|
1267
|
-
if (x < y) {
|
|
1268
|
-
return -1;
|
|
1269
|
-
}
|
|
1270
|
-
else if (x > y) {
|
|
1271
|
-
return 1;
|
|
1272
|
-
}
|
|
1273
|
-
else {
|
|
1274
|
-
return 0;
|
|
1275
|
-
}
|
|
1276
|
-
};
|
|
1277
|
-
export let _$n_compare = (a, b) => {
|
|
1278
|
-
if (a === b)
|
|
1279
|
-
return 0;
|
|
1280
|
-
let ta = typeAsInt(a);
|
|
1281
|
-
let tb = typeAsInt(b);
|
|
1282
|
-
if (ta === tb) {
|
|
1283
|
-
switch (ta) {
|
|
1284
|
-
case PseudoTypeIndex.nil:
|
|
1285
|
-
return 0;
|
|
1286
|
-
case PseudoTypeIndex.bool:
|
|
1287
|
-
return rawCompare(a, b);
|
|
1288
|
-
case PseudoTypeIndex.number:
|
|
1289
|
-
return rawCompare(a, b);
|
|
1290
|
-
case PseudoTypeIndex.keyword:
|
|
1291
|
-
return a.cmp(b);
|
|
1292
|
-
case PseudoTypeIndex.symbol:
|
|
1293
|
-
return rawCompare(a, b);
|
|
1294
|
-
case PseudoTypeIndex.string:
|
|
1295
|
-
return rawCompare(a, b);
|
|
1296
|
-
case PseudoTypeIndex.ref:
|
|
1297
|
-
return rawCompare(a.path, b.path);
|
|
1298
|
-
default:
|
|
1299
|
-
// TODO, need more accurate solution
|
|
1300
|
-
if (a < b) {
|
|
1301
|
-
return -1;
|
|
1302
|
-
}
|
|
1303
|
-
else if (a > b) {
|
|
1304
|
-
return 1;
|
|
1305
|
-
}
|
|
1306
|
-
else {
|
|
1307
|
-
return 0;
|
|
1308
|
-
}
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
else {
|
|
1312
|
-
return rawCompare(ta, tb);
|
|
1313
|
-
}
|
|
1314
|
-
};
|
|
1315
1216
|
export let _$n_map_$o_diff_new = (a, b) => {
|
|
1316
1217
|
if ((a instanceof CalcitMap || a instanceof CalcitSliceMap) && (b instanceof CalcitMap || b instanceof CalcitSliceMap)) {
|
|
1317
1218
|
return a.diffNew(b);
|
package/lib/custom-formatter.mjs
CHANGED
|
@@ -31,15 +31,15 @@ export let load_console_formatter_$x_ = () => {
|
|
|
31
31
|
return [
|
|
32
32
|
"div",
|
|
33
33
|
{ style: "color: hsl(280, 80%, 60%, 0.4)" },
|
|
34
|
-
obj.toString(true),
|
|
34
|
+
obj.toString(true, true),
|
|
35
35
|
["span", { style: "font-size: 80%; vertical-align: 0.7em; color: hsl(280, 80%, 60%, 0.8)" }, `${obj.len()}`],
|
|
36
36
|
];
|
|
37
37
|
}
|
|
38
38
|
if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
39
|
-
return ["div", { style: "color: hsl(280, 80%, 60%, 0.4)" }, obj.toString(true)];
|
|
39
|
+
return ["div", { style: "color: hsl(280, 80%, 60%, 0.4)" }, obj.toString(true, true)];
|
|
40
40
|
}
|
|
41
41
|
if (obj instanceof CalcitSet) {
|
|
42
|
-
return ["div", { style: "color: hsl(280, 80%, 60%, 0.4)" }, obj.toString()];
|
|
42
|
+
return ["div", { style: "color: hsl(280, 80%, 60%, 0.4)" }, obj.toString(true)];
|
|
43
43
|
}
|
|
44
44
|
if (obj instanceof CalcitRecord) {
|
|
45
45
|
let ret = ["div", { style: "color: hsl(280, 80%, 60%)" }, `%{} ${obj.name}`];
|
|
@@ -53,6 +53,13 @@ export let load_console_formatter_$x_ = () => {
|
|
|
53
53
|
}
|
|
54
54
|
return ret;
|
|
55
55
|
}
|
|
56
|
+
if (obj instanceof CalcitTuple) {
|
|
57
|
+
let ret = ["div", {}];
|
|
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.fst)]);
|
|
60
|
+
ret.push(["div", { style: "margin-left: 6px; display: inline-block;" }, embedObject(obj.snd)]);
|
|
61
|
+
return ret;
|
|
62
|
+
}
|
|
56
63
|
if (obj instanceof CalcitRef) {
|
|
57
64
|
return [
|
|
58
65
|
"div",
|
|
@@ -95,12 +102,6 @@ export let load_console_formatter_$x_ = () => {
|
|
|
95
102
|
}
|
|
96
103
|
return ret;
|
|
97
104
|
}
|
|
98
|
-
if (obj instanceof CalcitTuple) {
|
|
99
|
-
let ret = ["div", { style: "color: hsl(200, 90%, 60%)" }];
|
|
100
|
-
ret.push(["div", { style: "margin-left: 8px; display: inline-block;" }, embedObject(obj.fst)]);
|
|
101
|
-
ret.push(["div", { style: "margin-left: 8px; display: inline-block;" }, embedObject(obj.snd)]);
|
|
102
|
-
return ret;
|
|
103
|
-
}
|
|
104
105
|
if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
105
106
|
let ret = ["div", { style: "color: hsl(280, 80%, 60%)" }];
|
|
106
107
|
let pairs = obj.pairs();
|
package/lib/js-cirru.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "@calcit/ternary-tree";
|
|
2
2
|
import { writeCirruCode } from "@cirru/writer.ts";
|
|
3
|
-
import "./js-primes.mjs";
|
|
3
|
+
import { _$n_compare } from "./js-primes.mjs";
|
|
4
4
|
import { CalcitList, CalcitSliceList } from "./js-list.mjs";
|
|
5
5
|
import { CalcitRecord } from "./js-record.mjs";
|
|
6
6
|
import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
|
|
@@ -45,7 +45,14 @@ export let to_cirru_edn = (x) => {
|
|
|
45
45
|
}
|
|
46
46
|
if (x instanceof CalcitMap || x instanceof CalcitSliceMap) {
|
|
47
47
|
let buffer = ["{}"];
|
|
48
|
-
|
|
48
|
+
let pairs = [];
|
|
49
|
+
for (let pair of x.pairs()) {
|
|
50
|
+
pairs.push(pair);
|
|
51
|
+
}
|
|
52
|
+
pairs.sort((a, b) => {
|
|
53
|
+
return _$n_compare(a[0], b[0]);
|
|
54
|
+
});
|
|
55
|
+
for (let [k, v] of pairs) {
|
|
49
56
|
buffer.push([to_cirru_edn(k), to_cirru_edn(v)]);
|
|
50
57
|
}
|
|
51
58
|
return buffer;
|
|
@@ -60,6 +67,9 @@ export let to_cirru_edn = (x) => {
|
|
|
60
67
|
if (x instanceof CalcitSet) {
|
|
61
68
|
let buffer = ["#{}"];
|
|
62
69
|
let values = x.values();
|
|
70
|
+
values.sort((a, b) => {
|
|
71
|
+
return _$n_compare(a, b);
|
|
72
|
+
});
|
|
63
73
|
for (let idx = 0; idx < values.length; idx++) {
|
|
64
74
|
let y = values[idx];
|
|
65
75
|
buffer.push(to_cirru_edn(y));
|
package/lib/js-list.mjs
CHANGED
|
@@ -40,14 +40,14 @@ export class CalcitList {
|
|
|
40
40
|
slice(from, to) {
|
|
41
41
|
return new CalcitList(ternaryTree.slice(this.value, from, to));
|
|
42
42
|
}
|
|
43
|
-
toString(shorter = false) {
|
|
43
|
+
toString(shorter = false, disableJsDataWarning = false) {
|
|
44
44
|
let result = "";
|
|
45
45
|
for (let item of this.items()) {
|
|
46
46
|
if (shorter && isNestedCalcitData(item)) {
|
|
47
47
|
result = `${result} ${tipNestedCalcitData(item)}`;
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
|
-
result = `${result} ${toString(item, true)}`;
|
|
50
|
+
result = `${result} ${toString(item, true, disableJsDataWarning)}`;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
return `([]${result})`;
|
|
@@ -152,14 +152,14 @@ export class CalcitSliceList {
|
|
|
152
152
|
result.end = this.start + to;
|
|
153
153
|
return result;
|
|
154
154
|
}
|
|
155
|
-
toString(shorter = false) {
|
|
155
|
+
toString(shorter = false, disableJsDataWarning = false) {
|
|
156
156
|
let result = "";
|
|
157
157
|
for (let item of this.items()) {
|
|
158
158
|
if (shorter && isNestedCalcitData(item)) {
|
|
159
159
|
result = `${result} ${tipNestedCalcitData(item)}`;
|
|
160
160
|
}
|
|
161
161
|
else {
|
|
162
|
-
result = `${result} ${toString(item, true)}`;
|
|
162
|
+
result = `${result} ${toString(item, true, disableJsDataWarning)}`;
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
return `([]${result})`;
|
package/lib/js-map.mjs
CHANGED
|
@@ -46,16 +46,16 @@ export class CalcitMap {
|
|
|
46
46
|
}
|
|
47
47
|
return new CalcitMap(ret);
|
|
48
48
|
}
|
|
49
|
-
toString(shorter = false) {
|
|
49
|
+
toString(shorter = false, disableJsDataWarning = false) {
|
|
50
50
|
let itemsCode = "";
|
|
51
51
|
for (let [k, v] of this.pairs()) {
|
|
52
52
|
if (shorter) {
|
|
53
|
-
let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true);
|
|
54
|
-
let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true);
|
|
53
|
+
let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true, disableJsDataWarning);
|
|
54
|
+
let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true, disableJsDataWarning);
|
|
55
55
|
itemsCode = `${itemsCode} (${keyPart} ${valuePart})`;
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
58
|
-
itemsCode = `${itemsCode} (${toString(k, true)} ${toString(v, true)})`;
|
|
58
|
+
itemsCode = `${itemsCode} (${toString(k, true, disableJsDataWarning)} ${toString(v, true, disableJsDataWarning)})`;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
return `({}${itemsCode})`;
|
|
@@ -233,16 +233,16 @@ export class CalcitSliceMap {
|
|
|
233
233
|
return this.turnMap().dissoc(...args);
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
|
-
toString(shorter = false) {
|
|
236
|
+
toString(shorter = false, disableJsDataWarning = false) {
|
|
237
237
|
let itemsCode = "";
|
|
238
238
|
for (let [k, v] of this.pairs()) {
|
|
239
239
|
if (shorter) {
|
|
240
|
-
let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true);
|
|
241
|
-
let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true);
|
|
240
|
+
let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true, disableJsDataWarning);
|
|
241
|
+
let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true, disableJsDataWarning);
|
|
242
242
|
itemsCode = `${itemsCode} (${keyPart} ${valuePart})`;
|
|
243
243
|
}
|
|
244
244
|
else {
|
|
245
|
-
itemsCode = `${itemsCode} (${toString(k, true)} ${toString(v, true)})`;
|
|
245
|
+
itemsCode = `${itemsCode} (${toString(k, true, disableJsDataWarning)} ${toString(v, true, disableJsDataWarning)})`;
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
return `({}${itemsCode})`;
|
package/lib/js-primes.mjs
CHANGED
|
@@ -1,6 +1,106 @@
|
|
|
1
|
-
import "./calcit-data.mjs";
|
|
2
|
-
import "./js-list.mjs";
|
|
3
|
-
import "./js-record.mjs";
|
|
4
|
-
import "./js-map.mjs";
|
|
5
|
-
import "./js-set.mjs";
|
|
6
|
-
import "./js-tuple.mjs";
|
|
1
|
+
import { CalcitKeyword, CalcitSymbol, CalcitRef, CalcitRecur } from "./calcit-data.mjs";
|
|
2
|
+
import { CalcitList, CalcitSliceList } from "./js-list.mjs";
|
|
3
|
+
import { CalcitRecord } from "./js-record.mjs";
|
|
4
|
+
import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
|
|
5
|
+
import { CalcitSet as CalcitSet } from "./js-set.mjs";
|
|
6
|
+
import { CalcitTuple } from "./js-tuple.mjs";
|
|
7
|
+
var PseudoTypeIndex;
|
|
8
|
+
(function (PseudoTypeIndex) {
|
|
9
|
+
PseudoTypeIndex[PseudoTypeIndex["nil"] = 0] = "nil";
|
|
10
|
+
PseudoTypeIndex[PseudoTypeIndex["bool"] = 1] = "bool";
|
|
11
|
+
PseudoTypeIndex[PseudoTypeIndex["number"] = 2] = "number";
|
|
12
|
+
PseudoTypeIndex[PseudoTypeIndex["symbol"] = 3] = "symbol";
|
|
13
|
+
PseudoTypeIndex[PseudoTypeIndex["keyword"] = 4] = "keyword";
|
|
14
|
+
PseudoTypeIndex[PseudoTypeIndex["string"] = 5] = "string";
|
|
15
|
+
PseudoTypeIndex[PseudoTypeIndex["ref"] = 6] = "ref";
|
|
16
|
+
PseudoTypeIndex[PseudoTypeIndex["tuple"] = 7] = "tuple";
|
|
17
|
+
PseudoTypeIndex[PseudoTypeIndex["recur"] = 8] = "recur";
|
|
18
|
+
PseudoTypeIndex[PseudoTypeIndex["list"] = 9] = "list";
|
|
19
|
+
PseudoTypeIndex[PseudoTypeIndex["set"] = 10] = "set";
|
|
20
|
+
PseudoTypeIndex[PseudoTypeIndex["map"] = 11] = "map";
|
|
21
|
+
PseudoTypeIndex[PseudoTypeIndex["record"] = 12] = "record";
|
|
22
|
+
PseudoTypeIndex[PseudoTypeIndex["fn"] = 13] = "fn";
|
|
23
|
+
})(PseudoTypeIndex || (PseudoTypeIndex = {}));
|
|
24
|
+
let typeAsInt = (x) => {
|
|
25
|
+
// based on order used in Ord traint
|
|
26
|
+
if (x == null)
|
|
27
|
+
return PseudoTypeIndex.nil;
|
|
28
|
+
let t = typeof x;
|
|
29
|
+
if (t === "boolean")
|
|
30
|
+
return PseudoTypeIndex.bool;
|
|
31
|
+
if (t === "number")
|
|
32
|
+
return PseudoTypeIndex.number;
|
|
33
|
+
if (x instanceof CalcitSymbol)
|
|
34
|
+
return PseudoTypeIndex.symbol;
|
|
35
|
+
if (x instanceof CalcitKeyword)
|
|
36
|
+
return PseudoTypeIndex.keyword;
|
|
37
|
+
if (t === "string")
|
|
38
|
+
return PseudoTypeIndex.string;
|
|
39
|
+
if (x instanceof CalcitRef)
|
|
40
|
+
return PseudoTypeIndex.ref;
|
|
41
|
+
if (x instanceof CalcitTuple)
|
|
42
|
+
return PseudoTypeIndex.tuple;
|
|
43
|
+
if (x instanceof CalcitRecur)
|
|
44
|
+
return PseudoTypeIndex.recur;
|
|
45
|
+
if (x instanceof CalcitList || x instanceof CalcitSliceList)
|
|
46
|
+
return PseudoTypeIndex.list;
|
|
47
|
+
if (x instanceof CalcitSet)
|
|
48
|
+
return PseudoTypeIndex.set;
|
|
49
|
+
if (x instanceof CalcitMap || x instanceof CalcitSliceMap)
|
|
50
|
+
return PseudoTypeIndex.map;
|
|
51
|
+
if (x instanceof CalcitRecord)
|
|
52
|
+
return PseudoTypeIndex.record;
|
|
53
|
+
// proc, fn, macro, syntax, not distinguished
|
|
54
|
+
if (t === "function")
|
|
55
|
+
return PseudoTypeIndex.fn;
|
|
56
|
+
throw new Error("unknown type to compare");
|
|
57
|
+
};
|
|
58
|
+
let rawCompare = (x, y) => {
|
|
59
|
+
if (x < y) {
|
|
60
|
+
return -1;
|
|
61
|
+
}
|
|
62
|
+
else if (x > y) {
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
export let _$n_compare = (a, b) => {
|
|
70
|
+
if (a === b)
|
|
71
|
+
return 0;
|
|
72
|
+
let ta = typeAsInt(a);
|
|
73
|
+
let tb = typeAsInt(b);
|
|
74
|
+
if (ta === tb) {
|
|
75
|
+
switch (ta) {
|
|
76
|
+
case PseudoTypeIndex.nil:
|
|
77
|
+
return 0;
|
|
78
|
+
case PseudoTypeIndex.bool:
|
|
79
|
+
return rawCompare(a, b);
|
|
80
|
+
case PseudoTypeIndex.number:
|
|
81
|
+
return rawCompare(a, b);
|
|
82
|
+
case PseudoTypeIndex.keyword:
|
|
83
|
+
return rawCompare(a.value, b.value);
|
|
84
|
+
case PseudoTypeIndex.symbol:
|
|
85
|
+
return rawCompare(a, b);
|
|
86
|
+
case PseudoTypeIndex.string:
|
|
87
|
+
return rawCompare(a, b);
|
|
88
|
+
case PseudoTypeIndex.ref:
|
|
89
|
+
return rawCompare(a.path, b.path);
|
|
90
|
+
default:
|
|
91
|
+
// TODO, need more accurate solution
|
|
92
|
+
if (a < b) {
|
|
93
|
+
return -1;
|
|
94
|
+
}
|
|
95
|
+
else if (a > b) {
|
|
96
|
+
return 1;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
return rawCompare(ta, tb);
|
|
105
|
+
}
|
|
106
|
+
};
|
package/lib/js-record.mjs
CHANGED
|
@@ -51,10 +51,10 @@ export class CalcitRecord {
|
|
|
51
51
|
let idx = this.findIndex(k);
|
|
52
52
|
return idx >= 0;
|
|
53
53
|
}
|
|
54
|
-
toString() {
|
|
54
|
+
toString(disableJsDataWarning = false) {
|
|
55
55
|
let ret = "(%{} " + this.name;
|
|
56
56
|
for (let idx = 0; idx < this.fields.length; idx++) {
|
|
57
|
-
ret += " (" + this.fields[idx] + " " + toString(this.values[idx], true) + ")";
|
|
57
|
+
ret += " (" + this.fields[idx] + " " + toString(this.values[idx], true, disableJsDataWarning) + ")";
|
|
58
58
|
}
|
|
59
59
|
return ret + ")";
|
|
60
60
|
}
|
package/lib/js-set.mjs
CHANGED
|
@@ -83,10 +83,10 @@ export class CalcitSet {
|
|
|
83
83
|
let result = dissocMap(this.value, x0);
|
|
84
84
|
return new CalcitSet(result);
|
|
85
85
|
}
|
|
86
|
-
toString() {
|
|
86
|
+
toString(disableJsDataWarning = false) {
|
|
87
87
|
let itemsCode = "";
|
|
88
88
|
for (let k of ternaryTree.toKeys(this.value)) {
|
|
89
|
-
itemsCode = `${itemsCode} ${toString(k, true)}`;
|
|
89
|
+
itemsCode = `${itemsCode} ${toString(k, true, disableJsDataWarning)}`;
|
|
90
90
|
}
|
|
91
91
|
return `(#{}${itemsCode})`;
|
|
92
92
|
}
|
package/lib/js-tuple.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import "./js-primes.mjs";
|
|
2
1
|
import "@calcit/ternary-tree";
|
|
2
|
+
import "./js-primes.mjs";
|
|
3
|
+
import { toString } from "./calcit-data.mjs";
|
|
3
4
|
export class CalcitTuple {
|
|
4
5
|
constructor(a, b) {
|
|
5
6
|
this.fst = a;
|
|
@@ -28,7 +29,7 @@ export class CalcitTuple {
|
|
|
28
29
|
throw new Error("Tuple only have 2 elements");
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
|
-
toString() {
|
|
32
|
-
return `(&tuple ${this.fst
|
|
32
|
+
toString(disableJsDataWarning = false) {
|
|
33
|
+
return `(&tuple ${toString(this.fst, false, disableJsDataWarning)} ${toString(this.snd, false, disableJsDataWarning)})`;
|
|
33
34
|
}
|
|
34
35
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@calcit/procs",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.31",
|
|
4
4
|
"main": "./lib/calcit.procs.mjs",
|
|
5
5
|
"devDependencies": {
|
|
6
6
|
"@types/node": "^17.0.23",
|
|
7
|
-
"typescript": "^4.6.
|
|
7
|
+
"typescript": "^4.6.3"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"compile": "rm -rfv lib/* && tsc",
|
package/ts-src/calcit-data.mts
CHANGED
|
@@ -319,7 +319,7 @@ let hashFunction = (x: CalcitValue): Hash => {
|
|
|
319
319
|
// Dirty code to change ternary-tree behavior
|
|
320
320
|
overwriteHashGenerator(hashFunction);
|
|
321
321
|
|
|
322
|
-
export let toString = (x: CalcitValue, escaped: boolean): string => {
|
|
322
|
+
export let toString = (x: CalcitValue, escaped: boolean, disableJsDataWarning: boolean = false): string => {
|
|
323
323
|
if (x == null) {
|
|
324
324
|
return "nil";
|
|
325
325
|
}
|
|
@@ -351,26 +351,28 @@ export let toString = (x: CalcitValue, escaped: boolean): string => {
|
|
|
351
351
|
return x.toString();
|
|
352
352
|
}
|
|
353
353
|
if (x instanceof CalcitList || x instanceof CalcitSliceList) {
|
|
354
|
-
return x.toString();
|
|
354
|
+
return x.toString(false, disableJsDataWarning);
|
|
355
355
|
}
|
|
356
356
|
if (x instanceof CalcitMap || x instanceof CalcitSliceMap) {
|
|
357
|
-
return x.toString();
|
|
357
|
+
return x.toString(false, disableJsDataWarning);
|
|
358
358
|
}
|
|
359
359
|
if (x instanceof CalcitSet) {
|
|
360
|
-
return x.toString();
|
|
360
|
+
return x.toString(disableJsDataWarning);
|
|
361
361
|
}
|
|
362
362
|
if (x instanceof CalcitRecord) {
|
|
363
|
-
return x.toString();
|
|
363
|
+
return x.toString(disableJsDataWarning);
|
|
364
364
|
}
|
|
365
365
|
if (x instanceof CalcitRef) {
|
|
366
366
|
return x.toString();
|
|
367
367
|
}
|
|
368
368
|
if (x instanceof CalcitTuple) {
|
|
369
|
-
return x.toString();
|
|
369
|
+
return x.toString(disableJsDataWarning);
|
|
370
370
|
}
|
|
371
371
|
|
|
372
|
-
|
|
373
|
-
|
|
372
|
+
if (!disableJsDataWarning) {
|
|
373
|
+
console.warn("Unknown structure to string, better use `console.log`", x);
|
|
374
|
+
}
|
|
375
|
+
return `(#js ${JSON.stringify(x)})`;
|
|
374
376
|
};
|
|
375
377
|
|
|
376
378
|
export let to_js_data = (x: CalcitValue, addColon: boolean = false): any => {
|
package/ts-src/calcit.procs.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// CALCIT VERSION
|
|
2
|
-
export const calcit_version = "0.5.
|
|
2
|
+
export const calcit_version = "0.5.31";
|
|
3
3
|
|
|
4
4
|
import { overwriteComparator, initTernaryTreeMap } from "@calcit/ternary-tree";
|
|
5
5
|
import { parse, ICirruNode } from "@cirru/parser.ts";
|
|
@@ -31,6 +31,7 @@ export * from "./js-primes.mjs";
|
|
|
31
31
|
export * from "./js-tuple.mjs";
|
|
32
32
|
export * from "./custom-formatter.mjs";
|
|
33
33
|
export * from "./js-cirru.mjs";
|
|
34
|
+
export { _$n_compare } from "./js-primes.mjs";
|
|
34
35
|
|
|
35
36
|
import { CalcitList, CalcitSliceList, foldl } from "./js-list.mjs";
|
|
36
37
|
import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
|
|
@@ -1298,89 +1299,6 @@ export let _$n_map_$o_to_list = (m: CalcitValue): CalcitSliceList => {
|
|
|
1298
1299
|
}
|
|
1299
1300
|
};
|
|
1300
1301
|
|
|
1301
|
-
enum PseudoTypeIndex {
|
|
1302
|
-
nil,
|
|
1303
|
-
bool,
|
|
1304
|
-
number,
|
|
1305
|
-
symbol,
|
|
1306
|
-
keyword,
|
|
1307
|
-
string,
|
|
1308
|
-
ref,
|
|
1309
|
-
tuple,
|
|
1310
|
-
recur,
|
|
1311
|
-
list,
|
|
1312
|
-
set,
|
|
1313
|
-
map,
|
|
1314
|
-
record,
|
|
1315
|
-
fn,
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
let typeAsInt = (x: CalcitValue): number => {
|
|
1319
|
-
// based on order used in Ord traint
|
|
1320
|
-
if (x == null) return PseudoTypeIndex.nil;
|
|
1321
|
-
let t = typeof x;
|
|
1322
|
-
if (t === "boolean") return PseudoTypeIndex.bool;
|
|
1323
|
-
if (t === "number") return PseudoTypeIndex.number;
|
|
1324
|
-
if (x instanceof CalcitSymbol) return PseudoTypeIndex.symbol;
|
|
1325
|
-
if (x instanceof CalcitKeyword) return PseudoTypeIndex.keyword;
|
|
1326
|
-
if (t === "string") return PseudoTypeIndex.string;
|
|
1327
|
-
if (x instanceof CalcitRef) return PseudoTypeIndex.ref;
|
|
1328
|
-
if (x instanceof CalcitTuple) return PseudoTypeIndex.tuple;
|
|
1329
|
-
if (x instanceof CalcitRecur) return PseudoTypeIndex.recur;
|
|
1330
|
-
if (x instanceof CalcitList || x instanceof CalcitSliceList) return PseudoTypeIndex.list;
|
|
1331
|
-
if (x instanceof CalcitSet) return PseudoTypeIndex.set;
|
|
1332
|
-
if (x instanceof CalcitMap || x instanceof CalcitSliceMap) return PseudoTypeIndex.map;
|
|
1333
|
-
if (x instanceof CalcitRecord) return PseudoTypeIndex.record;
|
|
1334
|
-
// proc, fn, macro, syntax, not distinguished
|
|
1335
|
-
if (t === "function") return PseudoTypeIndex.fn;
|
|
1336
|
-
throw new Error("unknown type to compare");
|
|
1337
|
-
};
|
|
1338
|
-
|
|
1339
|
-
let rawCompare = (x: any, y: any): number => {
|
|
1340
|
-
if (x < y) {
|
|
1341
|
-
return -1;
|
|
1342
|
-
} else if (x > y) {
|
|
1343
|
-
return 1;
|
|
1344
|
-
} else {
|
|
1345
|
-
return 0;
|
|
1346
|
-
}
|
|
1347
|
-
};
|
|
1348
|
-
|
|
1349
|
-
export let _$n_compare = (a: CalcitValue, b: CalcitValue): number => {
|
|
1350
|
-
if (a === b) return 0;
|
|
1351
|
-
let ta = typeAsInt(a);
|
|
1352
|
-
let tb = typeAsInt(b);
|
|
1353
|
-
if (ta === tb) {
|
|
1354
|
-
switch (ta) {
|
|
1355
|
-
case PseudoTypeIndex.nil:
|
|
1356
|
-
return 0;
|
|
1357
|
-
case PseudoTypeIndex.bool:
|
|
1358
|
-
return rawCompare(a, b);
|
|
1359
|
-
case PseudoTypeIndex.number:
|
|
1360
|
-
return rawCompare(a, b);
|
|
1361
|
-
case PseudoTypeIndex.keyword:
|
|
1362
|
-
return (a as CalcitKeyword).cmp(b as CalcitKeyword);
|
|
1363
|
-
case PseudoTypeIndex.symbol:
|
|
1364
|
-
return rawCompare(a, b);
|
|
1365
|
-
case PseudoTypeIndex.string:
|
|
1366
|
-
return rawCompare(a, b);
|
|
1367
|
-
case PseudoTypeIndex.ref:
|
|
1368
|
-
return rawCompare((a as CalcitRef).path, (b as CalcitRef).path);
|
|
1369
|
-
default:
|
|
1370
|
-
// TODO, need more accurate solution
|
|
1371
|
-
if (a < b) {
|
|
1372
|
-
return -1;
|
|
1373
|
-
} else if (a > b) {
|
|
1374
|
-
return 1;
|
|
1375
|
-
} else {
|
|
1376
|
-
return 0;
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
} else {
|
|
1380
|
-
return rawCompare(ta, tb);
|
|
1381
|
-
}
|
|
1382
|
-
};
|
|
1383
|
-
|
|
1384
1302
|
export let _$n_map_$o_diff_new = (a: CalcitValue, b: CalcitValue): CalcitMap => {
|
|
1385
1303
|
if ((a instanceof CalcitMap || a instanceof CalcitSliceMap) && (b instanceof CalcitMap || b instanceof CalcitSliceMap)) {
|
|
1386
1304
|
return a.diffNew(b);
|
|
@@ -44,15 +44,15 @@ export let load_console_formatter_$x_ = () => {
|
|
|
44
44
|
return [
|
|
45
45
|
"div",
|
|
46
46
|
{ style: "color: hsl(280, 80%, 60%, 0.4)" },
|
|
47
|
-
obj.toString(true),
|
|
47
|
+
obj.toString(true, true),
|
|
48
48
|
["span", { style: "font-size: 80%; vertical-align: 0.7em; color: hsl(280, 80%, 60%, 0.8)" }, `${obj.len()}`],
|
|
49
49
|
];
|
|
50
50
|
}
|
|
51
51
|
if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
52
|
-
return ["div", { style: "color: hsl(280, 80%, 60%, 0.4)" }, obj.toString(true)];
|
|
52
|
+
return ["div", { style: "color: hsl(280, 80%, 60%, 0.4)" }, obj.toString(true, true)];
|
|
53
53
|
}
|
|
54
54
|
if (obj instanceof CalcitSet) {
|
|
55
|
-
return ["div", { style: "color: hsl(280, 80%, 60%, 0.4)" }, obj.toString()];
|
|
55
|
+
return ["div", { style: "color: hsl(280, 80%, 60%, 0.4)" }, obj.toString(true)];
|
|
56
56
|
}
|
|
57
57
|
if (obj instanceof CalcitRecord) {
|
|
58
58
|
let ret: any[] = ["div", { style: "color: hsl(280, 80%, 60%)" }, `%{} ${obj.name}`];
|
|
@@ -66,6 +66,13 @@ export let load_console_formatter_$x_ = () => {
|
|
|
66
66
|
}
|
|
67
67
|
return ret;
|
|
68
68
|
}
|
|
69
|
+
if (obj instanceof CalcitTuple) {
|
|
70
|
+
let ret: any[] = ["div", {}];
|
|
71
|
+
ret.push(["div", { style: "display: inline-block; color: hsl(300, 100%, 40%); " }, "::"]);
|
|
72
|
+
ret.push(["div", { style: "margin-left: 6px; display: inline-block;" }, embedObject(obj.fst)]);
|
|
73
|
+
ret.push(["div", { style: "margin-left: 6px; display: inline-block;" }, embedObject(obj.snd)]);
|
|
74
|
+
return ret;
|
|
75
|
+
}
|
|
69
76
|
if (obj instanceof CalcitRef) {
|
|
70
77
|
return [
|
|
71
78
|
"div",
|
|
@@ -110,12 +117,6 @@ export let load_console_formatter_$x_ = () => {
|
|
|
110
117
|
}
|
|
111
118
|
return ret;
|
|
112
119
|
}
|
|
113
|
-
if (obj instanceof CalcitTuple) {
|
|
114
|
-
let ret: any[] = ["div", { style: "color: hsl(200, 90%, 60%)" }];
|
|
115
|
-
ret.push(["div", { style: "margin-left: 8px; display: inline-block;" }, embedObject(obj.fst)]);
|
|
116
|
-
ret.push(["div", { style: "margin-left: 8px; display: inline-block;" }, embedObject(obj.snd)]);
|
|
117
|
-
return ret;
|
|
118
|
-
}
|
|
119
120
|
if (obj instanceof CalcitMap || obj instanceof CalcitSliceMap) {
|
|
120
121
|
let ret: any[] = ["div", { style: "color: hsl(280, 80%, 60%)" }];
|
|
121
122
|
let pairs = obj.pairs();
|
package/ts-src/js-cirru.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { overwriteComparator, initTernaryTreeMap } from "@calcit/ternary-tree";
|
|
2
2
|
import { CirruWriterNode, writeCirruCode } from "@cirru/writer.ts";
|
|
3
3
|
|
|
4
|
-
import { CalcitValue } from "./js-primes.mjs";
|
|
4
|
+
import { CalcitValue, _$n_compare } from "./js-primes.mjs";
|
|
5
5
|
import { CalcitList, CalcitSliceList } from "./js-list.mjs";
|
|
6
6
|
import { CalcitRecord } from "./js-record.mjs";
|
|
7
7
|
import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
|
|
@@ -50,7 +50,14 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
|
|
|
50
50
|
}
|
|
51
51
|
if (x instanceof CalcitMap || x instanceof CalcitSliceMap) {
|
|
52
52
|
let buffer: CirruEdnFormat = ["{}"];
|
|
53
|
-
|
|
53
|
+
let pairs: [CalcitValue, CalcitValue][] = [];
|
|
54
|
+
for (let pair of x.pairs()) {
|
|
55
|
+
pairs.push(pair);
|
|
56
|
+
}
|
|
57
|
+
pairs.sort((a, b) => {
|
|
58
|
+
return _$n_compare(a[0], b[0]);
|
|
59
|
+
});
|
|
60
|
+
for (let [k, v] of pairs) {
|
|
54
61
|
buffer.push([to_cirru_edn(k), to_cirru_edn(v)]);
|
|
55
62
|
}
|
|
56
63
|
return buffer;
|
|
@@ -65,6 +72,9 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
|
|
|
65
72
|
if (x instanceof CalcitSet) {
|
|
66
73
|
let buffer: CirruEdnFormat = ["#{}"];
|
|
67
74
|
let values = x.values();
|
|
75
|
+
values.sort((a, b) => {
|
|
76
|
+
return _$n_compare(a, b);
|
|
77
|
+
});
|
|
68
78
|
for (let idx = 0; idx < values.length; idx++) {
|
|
69
79
|
let y = values[idx];
|
|
70
80
|
buffer.push(to_cirru_edn(y));
|
package/ts-src/js-list.mts
CHANGED
|
@@ -58,13 +58,13 @@ export class CalcitList {
|
|
|
58
58
|
slice(from: number, to: number) {
|
|
59
59
|
return new CalcitList(ternaryTree.slice(this.value, from, to));
|
|
60
60
|
}
|
|
61
|
-
toString(shorter = false): string {
|
|
61
|
+
toString(shorter = false, disableJsDataWarning: boolean = false): string {
|
|
62
62
|
let result = "";
|
|
63
63
|
for (let item of this.items()) {
|
|
64
64
|
if (shorter && isNestedCalcitData(item)) {
|
|
65
65
|
result = `${result} ${tipNestedCalcitData(item)}`;
|
|
66
66
|
} else {
|
|
67
|
-
result = `${result} ${toString(item, true)}`;
|
|
67
|
+
result = `${result} ${toString(item, true, disableJsDataWarning)}`;
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
return `([]${result})`;
|
|
@@ -171,13 +171,13 @@ export class CalcitSliceList {
|
|
|
171
171
|
result.end = this.start + to;
|
|
172
172
|
return result;
|
|
173
173
|
}
|
|
174
|
-
toString(shorter = false): string {
|
|
174
|
+
toString(shorter = false, disableJsDataWarning = false): string {
|
|
175
175
|
let result = "";
|
|
176
176
|
for (let item of this.items()) {
|
|
177
177
|
if (shorter && isNestedCalcitData(item)) {
|
|
178
178
|
result = `${result} ${tipNestedCalcitData(item)}`;
|
|
179
179
|
} else {
|
|
180
|
-
result = `${result} ${toString(item, true)}`;
|
|
180
|
+
result = `${result} ${toString(item, true, disableJsDataWarning)}`;
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
return `([]${result})`;
|
package/ts-src/js-map.mts
CHANGED
|
@@ -66,15 +66,15 @@ export class CalcitMap {
|
|
|
66
66
|
}
|
|
67
67
|
return new CalcitMap(ret);
|
|
68
68
|
}
|
|
69
|
-
toString(shorter = false) {
|
|
69
|
+
toString(shorter = false, disableJsDataWarning = false) {
|
|
70
70
|
let itemsCode = "";
|
|
71
71
|
for (let [k, v] of this.pairs()) {
|
|
72
72
|
if (shorter) {
|
|
73
|
-
let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true);
|
|
74
|
-
let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true);
|
|
73
|
+
let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true, disableJsDataWarning);
|
|
74
|
+
let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true, disableJsDataWarning);
|
|
75
75
|
itemsCode = `${itemsCode} (${keyPart} ${valuePart})`;
|
|
76
76
|
} else {
|
|
77
|
-
itemsCode = `${itemsCode} (${toString(k, true)} ${toString(v, true)})`;
|
|
77
|
+
itemsCode = `${itemsCode} (${toString(k, true, disableJsDataWarning)} ${toString(v, true, disableJsDataWarning)})`;
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
return `({}${itemsCode})`;
|
|
@@ -252,15 +252,15 @@ export class CalcitSliceMap {
|
|
|
252
252
|
return this.turnMap().dissoc(...args);
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
|
-
toString(shorter = false) {
|
|
255
|
+
toString(shorter = false, disableJsDataWarning = false) {
|
|
256
256
|
let itemsCode = "";
|
|
257
257
|
for (let [k, v] of this.pairs()) {
|
|
258
258
|
if (shorter) {
|
|
259
|
-
let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true);
|
|
260
|
-
let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true);
|
|
259
|
+
let keyPart = isNestedCalcitData(k) ? tipNestedCalcitData(k) : toString(k, true, disableJsDataWarning);
|
|
260
|
+
let valuePart = isNestedCalcitData(v) ? tipNestedCalcitData(v) : toString(v, true, disableJsDataWarning);
|
|
261
261
|
itemsCode = `${itemsCode} (${keyPart} ${valuePart})`;
|
|
262
262
|
} else {
|
|
263
|
-
itemsCode = `${itemsCode} (${toString(k, true)} ${toString(v, true)})`;
|
|
263
|
+
itemsCode = `${itemsCode} (${toString(k, true, disableJsDataWarning)} ${toString(v, true, disableJsDataWarning)})`;
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
return `({}${itemsCode})`;
|
package/ts-src/js-primes.mts
CHANGED
|
@@ -22,3 +22,86 @@ export type CalcitValue =
|
|
|
22
22
|
| CalcitRecur // should not be exposed to function
|
|
23
23
|
| CalcitRecord
|
|
24
24
|
| null;
|
|
25
|
+
|
|
26
|
+
enum PseudoTypeIndex {
|
|
27
|
+
nil,
|
|
28
|
+
bool,
|
|
29
|
+
number,
|
|
30
|
+
symbol,
|
|
31
|
+
keyword,
|
|
32
|
+
string,
|
|
33
|
+
ref,
|
|
34
|
+
tuple,
|
|
35
|
+
recur,
|
|
36
|
+
list,
|
|
37
|
+
set,
|
|
38
|
+
map,
|
|
39
|
+
record,
|
|
40
|
+
fn,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let typeAsInt = (x: CalcitValue): number => {
|
|
44
|
+
// based on order used in Ord traint
|
|
45
|
+
if (x == null) return PseudoTypeIndex.nil;
|
|
46
|
+
let t = typeof x;
|
|
47
|
+
if (t === "boolean") return PseudoTypeIndex.bool;
|
|
48
|
+
if (t === "number") return PseudoTypeIndex.number;
|
|
49
|
+
if (x instanceof CalcitSymbol) return PseudoTypeIndex.symbol;
|
|
50
|
+
if (x instanceof CalcitKeyword) return PseudoTypeIndex.keyword;
|
|
51
|
+
if (t === "string") return PseudoTypeIndex.string;
|
|
52
|
+
if (x instanceof CalcitRef) return PseudoTypeIndex.ref;
|
|
53
|
+
if (x instanceof CalcitTuple) return PseudoTypeIndex.tuple;
|
|
54
|
+
if (x instanceof CalcitRecur) return PseudoTypeIndex.recur;
|
|
55
|
+
if (x instanceof CalcitList || x instanceof CalcitSliceList) return PseudoTypeIndex.list;
|
|
56
|
+
if (x instanceof CalcitSet) return PseudoTypeIndex.set;
|
|
57
|
+
if (x instanceof CalcitMap || x instanceof CalcitSliceMap) return PseudoTypeIndex.map;
|
|
58
|
+
if (x instanceof CalcitRecord) return PseudoTypeIndex.record;
|
|
59
|
+
// proc, fn, macro, syntax, not distinguished
|
|
60
|
+
if (t === "function") return PseudoTypeIndex.fn;
|
|
61
|
+
throw new Error("unknown type to compare");
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
let rawCompare = (x: any, y: any): number => {
|
|
65
|
+
if (x < y) {
|
|
66
|
+
return -1;
|
|
67
|
+
} else if (x > y) {
|
|
68
|
+
return 1;
|
|
69
|
+
} else {
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export let _$n_compare = (a: CalcitValue, b: CalcitValue): number => {
|
|
75
|
+
if (a === b) return 0;
|
|
76
|
+
let ta = typeAsInt(a);
|
|
77
|
+
let tb = typeAsInt(b);
|
|
78
|
+
if (ta === tb) {
|
|
79
|
+
switch (ta) {
|
|
80
|
+
case PseudoTypeIndex.nil:
|
|
81
|
+
return 0;
|
|
82
|
+
case PseudoTypeIndex.bool:
|
|
83
|
+
return rawCompare(a, b);
|
|
84
|
+
case PseudoTypeIndex.number:
|
|
85
|
+
return rawCompare(a, b);
|
|
86
|
+
case PseudoTypeIndex.keyword:
|
|
87
|
+
return rawCompare((a as CalcitKeyword).value, (b as CalcitKeyword).value);
|
|
88
|
+
case PseudoTypeIndex.symbol:
|
|
89
|
+
return rawCompare(a, b);
|
|
90
|
+
case PseudoTypeIndex.string:
|
|
91
|
+
return rawCompare(a, b);
|
|
92
|
+
case PseudoTypeIndex.ref:
|
|
93
|
+
return rawCompare((a as CalcitRef).path, (b as CalcitRef).path);
|
|
94
|
+
default:
|
|
95
|
+
// TODO, need more accurate solution
|
|
96
|
+
if (a < b) {
|
|
97
|
+
return -1;
|
|
98
|
+
} else if (a > b) {
|
|
99
|
+
return 1;
|
|
100
|
+
} else {
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
return rawCompare(ta, tb);
|
|
106
|
+
}
|
|
107
|
+
};
|
package/ts-src/js-record.mts
CHANGED
|
@@ -54,10 +54,10 @@ export class CalcitRecord {
|
|
|
54
54
|
let idx = this.findIndex(k);
|
|
55
55
|
return idx >= 0;
|
|
56
56
|
}
|
|
57
|
-
toString(): string {
|
|
57
|
+
toString(disableJsDataWarning: boolean = false): string {
|
|
58
58
|
let ret = "(%{} " + this.name;
|
|
59
59
|
for (let idx = 0; idx < this.fields.length; idx++) {
|
|
60
|
-
ret += " (" + this.fields[idx] + " " + toString(this.values[idx], true) + ")";
|
|
60
|
+
ret += " (" + this.fields[idx] + " " + toString(this.values[idx], true, disableJsDataWarning) + ")";
|
|
61
61
|
}
|
|
62
62
|
return ret + ")";
|
|
63
63
|
}
|
package/ts-src/js-set.mts
CHANGED
|
@@ -105,10 +105,10 @@ export class CalcitSet {
|
|
|
105
105
|
return new CalcitSet(result);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
toString() {
|
|
108
|
+
toString(disableJsDataWarning: boolean = false) {
|
|
109
109
|
let itemsCode = "";
|
|
110
110
|
for (let k of ternaryTree.toKeys(this.value)) {
|
|
111
|
-
itemsCode = `${itemsCode} ${toString(k, true)}`;
|
|
111
|
+
itemsCode = `${itemsCode} ${toString(k, true, disableJsDataWarning)}`;
|
|
112
112
|
}
|
|
113
113
|
return `(#{}${itemsCode})`;
|
|
114
114
|
}
|
package/ts-src/js-tuple.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { CalcitValue } from "./js-primes.mjs";
|
|
2
|
-
|
|
3
1
|
import { Hash } from "@calcit/ternary-tree";
|
|
4
2
|
|
|
3
|
+
import { CalcitValue } from "./js-primes.mjs";
|
|
4
|
+
import { toString } from "./calcit-data.mjs";
|
|
5
|
+
|
|
5
6
|
export class CalcitTuple {
|
|
6
7
|
fst: CalcitValue;
|
|
7
8
|
snd: CalcitValue;
|
|
@@ -29,7 +30,7 @@ export class CalcitTuple {
|
|
|
29
30
|
throw new Error("Tuple only have 2 elements");
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
|
-
toString(): string {
|
|
33
|
-
return `(&tuple ${this.fst
|
|
33
|
+
toString(disableJsDataWarning: boolean = false): string {
|
|
34
|
+
return `(&tuple ${toString(this.fst, false, disableJsDataWarning)} ${toString(this.snd, false, disableJsDataWarning)})`;
|
|
34
35
|
}
|
|
35
36
|
}
|
package/.vscode/settings.json
DELETED