@calcit/procs 0.13.0 → 0.13.2

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.
Files changed (35) hide show
  1. package/.yarn/install-state.gz +0 -0
  2. package/editing-history/202608061340-release-0.13.1.md +6 -0
  3. package/editing-history/202608061714-struct-enum-data-model-v2.md +39 -0
  4. package/editing-history/202608061731-release-0.13.2.md +18 -0
  5. package/history/202608061335-recursive-nominal-display.md +28 -0
  6. package/history/202608061433-required-record-field-access.md +32 -0
  7. package/lib/calcit-data.mjs +24 -24
  8. package/lib/calcit.procs.d.mts +43 -43
  9. package/lib/calcit.procs.mjs +165 -168
  10. package/lib/custom-formatter.mjs +38 -27
  11. package/lib/js-cirru.mjs +25 -25
  12. package/lib/js-enum-def.d.mts +11 -0
  13. package/lib/{js-enum.mjs → js-enum-def.mjs} +3 -3
  14. package/lib/{js-tuple.d.mts → js-enum-value.d.mts} +6 -7
  15. package/lib/{js-tuple.mjs → js-enum-value.mjs} +8 -15
  16. package/lib/js-list.mjs +6 -6
  17. package/lib/js-primes.d.mts +5 -5
  18. package/lib/js-primes.mjs +16 -16
  19. package/lib/{js-struct.d.mts → js-struct-def.d.mts} +2 -2
  20. package/lib/{js-struct.mjs → js-struct-def.mjs} +6 -6
  21. package/lib/{js-record.d.mts → js-struct-value.d.mts} +16 -15
  22. package/lib/{js-record.mjs → js-struct-value.mjs} +67 -59
  23. package/lib/package.json +1 -1
  24. package/package.json +1 -1
  25. package/ts-src/calcit-data.mts +24 -24
  26. package/ts-src/calcit.procs.mts +165 -168
  27. package/ts-src/custom-formatter.mts +65 -40
  28. package/ts-src/js-cirru.mts +26 -26
  29. package/ts-src/{js-enum.mts → js-enum-def.mts} +7 -7
  30. package/ts-src/{js-tuple.mts → js-enum-value.mts} +12 -19
  31. package/ts-src/js-list.mts +6 -6
  32. package/ts-src/js-primes.mts +16 -16
  33. package/ts-src/{js-struct.mts → js-struct-def.mts} +7 -7
  34. package/ts-src/{js-record.mts → js-struct-value.mts} +72 -66
  35. package/lib/js-enum.d.mts +0 -11
@@ -2,11 +2,13 @@ import { CalcitValue, isLiteral } from "./js-primes.mjs";
2
2
  import { CalcitSymbol, CalcitTag } from "./calcit-data.mjs";
3
3
  import { CalcitRef } from "./js-ref.mjs";
4
4
 
5
- import { CalcitRecord } from "./js-record.mjs";
5
+ import { CalcitStructValue } from "./js-struct-value.mjs";
6
+ import { CalcitStructDef } from "./js-struct-def.mjs";
7
+ import { CalcitEnumDef } from "./js-enum-def.mjs";
6
8
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
7
9
  import { CalcitList, CalcitSliceList } from "./js-list.mjs";
8
10
  import { CalcitSet } from "./js-set.mjs";
9
- import { CalcitTuple } from "./js-tuple.mjs";
11
+ import { CalcitEnumValue } from "./js-enum-value.mjs";
10
12
  import { CalcitCirruQuote } from "./js-cirru.mjs";
11
13
 
12
14
  declare global {
@@ -179,44 +181,38 @@ export let load_console_formatter_$x_ = () => {
179
181
  preview
180
182
  );
181
183
  }
182
- if (obj instanceof CalcitRecord) {
183
- if (obj.structRef.impls.length > 0) {
184
- let ret: any[] = div(
185
- { color: hsl(280, 80, 60, 0.4), maxWidth: "100%" },
186
- span({}, "%{}"),
187
- span({ marginLeft: "6px" }, embedObject(obj.structRef.impls[0])),
188
- span({ marginLeft: "6px" }, embedObject(obj.name)),
189
- span({ marginLeft: "6px" }, `...`)
190
- );
191
- return ret;
192
- } else {
193
- let ret: any[] = div({ color: hsl(280, 80, 60, 0.4), maxWidth: "100%" }, `%{} ${obj.name} ...`);
194
- return ret;
195
- }
184
+ if (obj instanceof CalcitStructValue) {
185
+ const name = new CalcitSymbol(obj.name.value);
186
+ return div({ color: hsl(280, 80, 60, 0.4), maxWidth: "100%" }, "%{} ", embedObject(name), " ...");
196
187
  }
197
- if (obj instanceof CalcitTuple) {
198
- if (obj.impls.length > 0) {
199
- let ret: any[] = div(
200
- { marginRight: "16px" },
201
- div({ display: "inline-block", color: hsl(300, 100, 40) }, "%::"),
202
- div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.impls[0])),
203
- div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.tag))
204
- );
205
- for (let idx = 0; idx < obj.extra.length; idx++) {
206
- ret.push(div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.extra[idx])));
207
- }
208
- return ret;
209
- } else {
210
- let ret: any[] = div(
211
- { marginRight: "16px" },
212
- div({ display: "inline-block", color: hsl(300, 100, 40) }, "::"),
213
- div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.tag))
214
- );
215
- for (let idx = 0; idx < obj.extra.length; idx++) {
216
- ret.push(div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.extra[idx])));
217
- }
218
- return ret;
188
+ if (obj instanceof CalcitStructDef) {
189
+ return div(
190
+ { color: hsl(280, 80, 60, 0.4), maxWidth: "100%" },
191
+ "%struct-def ",
192
+ embedObject(new CalcitSymbol(obj.name.value)),
193
+ " ..."
194
+ );
195
+ }
196
+ if (obj instanceof CalcitEnumDef) {
197
+ return div(
198
+ { color: hsl(280, 80, 60, 0.4), maxWidth: "100%" },
199
+ "%enum-def ",
200
+ embedObject(new CalcitSymbol(obj.prototype.name.value)),
201
+ " ..."
202
+ );
203
+ }
204
+ if (obj instanceof CalcitEnumValue) {
205
+ const enumName = obj.enumPrototype == null ? "_" : obj.enumPrototype.name();
206
+ let ret: any[] = div(
207
+ { marginRight: "16px" },
208
+ div({ display: "inline-block", color: hsl(300, 100, 40) }, "%::"),
209
+ div({ marginLeft: "6px", display: "inline-block" }, embedObject(new CalcitSymbol(enumName))),
210
+ div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.tag))
211
+ );
212
+ for (let idx = 0; idx < obj.extra.length; idx++) {
213
+ ret.push(div({ marginLeft: "6px", display: "inline-block" }, embedObject(obj.extra[idx])));
219
214
  }
215
+ return ret;
220
216
  }
221
217
  if (obj instanceof CalcitRef) {
222
218
  return div(
@@ -252,9 +248,12 @@ export let load_console_formatter_$x_ = () => {
252
248
  let hasCollection = obj.nestedDataInChildren();
253
249
  return obj.len() > 0 && hasCollection;
254
250
  }
255
- if (obj instanceof CalcitRecord) {
251
+ if (obj instanceof CalcitStructValue) {
256
252
  return obj.fields.length > 0;
257
253
  }
254
+ if (obj instanceof CalcitStructDef || obj instanceof CalcitEnumDef) {
255
+ return obj instanceof CalcitStructDef ? obj.fields.length > 0 : obj.prototype.fields.length > 0;
256
+ }
258
257
  return false;
259
258
  },
260
259
  body: (obj, config) => {
@@ -317,7 +316,7 @@ export let load_console_formatter_$x_ = () => {
317
316
  }
318
317
  return ret;
319
318
  }
320
- if (obj instanceof CalcitRecord) {
319
+ if (obj instanceof CalcitStructValue) {
321
320
  let ret: any[] = table({ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" });
322
321
  for (let idx = 0; idx < obj.fields.length; idx++) {
323
322
  ret.push(
@@ -330,6 +329,32 @@ export let load_console_formatter_$x_ = () => {
330
329
  }
331
330
  return ret;
332
331
  }
332
+ if (obj instanceof CalcitStructDef) {
333
+ let ret: any[] = table({ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" });
334
+ for (let idx = 0; idx < obj.fields.length; idx++) {
335
+ ret.push(
336
+ tr(
337
+ {},
338
+ td({ paddingLeft: "8px", verticalAlign: "top", whiteSpace: "pre", minWidth: "40px" }, embedObject(obj.fields[idx])),
339
+ td({ paddingLeft: "8px" }, embedObject(obj.fieldTypes[idx]))
340
+ )
341
+ );
342
+ }
343
+ return ret;
344
+ }
345
+ if (obj instanceof CalcitEnumDef) {
346
+ let ret: any[] = table({ color: hsl(280, 80, 60), borderLeft: "1px solid #eee" });
347
+ for (let idx = 0; idx < obj.prototype.fields.length; idx++) {
348
+ ret.push(
349
+ tr(
350
+ {},
351
+ td({ paddingLeft: "8px", verticalAlign: "top", whiteSpace: "pre", minWidth: "40px" }, embedObject(obj.prototype.fields[idx])),
352
+ td({ paddingLeft: "8px" }, embedObject(obj.prototype.values[idx]))
353
+ )
354
+ );
355
+ }
356
+ return ret;
357
+ }
333
358
 
334
359
  return null;
335
360
  },
@@ -3,12 +3,12 @@ import { CirruWriterNode, writeCirruCode, writeCirruOneLiner } from "@cirru/writ
3
3
 
4
4
  import { CalcitValue, isLiteral, _$n_compare } from "./js-primes.mjs";
5
5
  import { CalcitList, CalcitSliceList } from "./js-list.mjs";
6
- import { CalcitRecord } from "./js-record.mjs";
6
+ import { CalcitStructValue } from "./js-struct-value.mjs";
7
7
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
8
8
  import { CalcitSet } from "./js-set.mjs";
9
9
  import { CalcitTag, CalcitSymbol, CalcitRecur, newTag } from "./calcit-data.mjs";
10
- import { CalcitTuple } from "./js-tuple.mjs";
11
- import { CalcitEnum } from "./js-enum.mjs";
10
+ import { CalcitEnumValue } from "./js-enum-value.mjs";
11
+ import { CalcitEnumDef } from "./js-enum-def.mjs";
12
12
  import { CalcitImpl } from "./js-impl.mjs";
13
13
  import { CalcitRef } from "./js-ref.mjs";
14
14
  import { deepEqual } from "@calcit/ternary-tree/lib/utils.mjs";
@@ -151,7 +151,7 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
151
151
  }
152
152
  return buffer;
153
153
  }
154
- if (x instanceof CalcitRecord) {
154
+ if (x instanceof CalcitStructValue) {
155
155
  let buffer: [string, CirruEdnFormat][] = [];
156
156
  for (let idx = 0; idx < x.fields.length; idx++) {
157
157
  buffer.push([x.fields[idx].toString(), to_cirru_edn(x.values[idx])]);
@@ -174,7 +174,7 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
174
174
  }
175
175
  return buffer;
176
176
  }
177
- if (x instanceof CalcitTuple) {
177
+ if (x instanceof CalcitEnumValue) {
178
178
  if (x.tag instanceof CalcitSymbol && x.tag.value === "quote") {
179
179
  // turn `x.snd` with CalcitList into raw Cirru nodes, which is in plain Array
180
180
  return ["quote", toWriterNode(x.get(1) as any)] as CirruEdnFormat;
@@ -182,7 +182,7 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
182
182
  let enumTag = unwrap_enum_prototype_local(x.enumPrototype).name.toString();
183
183
  if (x.tag instanceof CalcitTag) {
184
184
  return ["%::", enumTag, x.tag.toString(), ...x.extra.map(to_cirru_edn)];
185
- } else if (x.tag instanceof CalcitRecord) {
185
+ } else if (x.tag instanceof CalcitStructValue) {
186
186
  return ["%::", enumTag, x.tag.name.toString(), ...x.extra.map(to_cirru_edn)];
187
187
  } else if (x.tag instanceof CalcitImpl) {
188
188
  return ["%::", enumTag, x.tag.name.toString(), ...x.extra.map(to_cirru_edn)];
@@ -191,7 +191,7 @@ export let to_cirru_edn = (x: CalcitValue): CirruEdnFormat => {
191
191
  }
192
192
  } else if (x.tag instanceof CalcitTag) {
193
193
  return ["::", x.tag.toString(), ...x.extra.map(to_cirru_edn)];
194
- } else if (x.tag instanceof CalcitRecord) {
194
+ } else if (x.tag instanceof CalcitStructValue) {
195
195
  return ["::", x.tag.name.toString(), ...x.extra.map(to_cirru_edn)];
196
196
  } else if (x.tag instanceof CalcitImpl) {
197
197
  return ["::", x.tag.name.toString(), ...x.extra.map(to_cirru_edn)];
@@ -230,9 +230,12 @@ let extractFieldTag = (x: string) => {
230
230
  let resolveEnumPrototype = (enumName: string, options: CalcitValue) => {
231
231
  if (options instanceof CalcitMap || options instanceof CalcitSliceMap) {
232
232
  let value = options.get(extractFieldTag(enumName));
233
- if (value instanceof CalcitEnum || value instanceof CalcitRecord) {
233
+ if (value instanceof CalcitEnumDef) {
234
234
  return value;
235
235
  }
236
+ if (value instanceof CalcitStructValue) {
237
+ throw new Error(`Enum ${enumName} uses a legacy struct prototype; provide an EnumDef produced by defenum`);
238
+ }
236
239
  if (value != null) {
237
240
  throw new Error(`Expected enum prototype for ${enumName}, got: ${value}`);
238
241
  }
@@ -240,20 +243,17 @@ let resolveEnumPrototype = (enumName: string, options: CalcitValue) => {
240
243
  return null;
241
244
  };
242
245
 
243
- // local helper to unwrap an enum prototype value to a CalcitRecord prototype
244
- const unwrap_enum_prototype_local = (enumPrototype: CalcitValue): CalcitRecord => {
245
- if (enumPrototype instanceof CalcitEnum) {
246
+ // local helper to inspect an EnumDef's variant prototype
247
+ const unwrap_enum_prototype_local = (enumPrototype: CalcitValue): CalcitStructValue => {
248
+ if (enumPrototype instanceof CalcitEnumDef) {
246
249
  return enumPrototype.prototype;
247
250
  }
248
- if (enumPrototype instanceof CalcitRecord) {
249
- return enumPrototype;
250
- }
251
- throw new Error(`expected enum prototype`);
251
+ throw new Error(`expected an EnumDef produced by defenum`);
252
252
  };
253
253
 
254
254
  const tag_to_string = (tag: CalcitValue): string => {
255
255
  if (tag instanceof CalcitTag) return tag.toString();
256
- if (tag instanceof CalcitRecord) return tag.name.toString();
256
+ if (tag instanceof CalcitStructValue) return tag.name.toString();
257
257
  throw new Error(`Unsupported tag for EDN: ${tag}`);
258
258
  };
259
259
 
@@ -321,7 +321,7 @@ const extract_cirru_edn_inner = (x: CirruEdnFormat, options: CalcitValue, preser
321
321
  if (x[0] === "%{}") {
322
322
  let name = x[1];
323
323
  if (typeof name != "string") {
324
- throw new Error(`Expected string for record name, got: ${name}`);
324
+ throw new Error(`Expected string for struct name, got: ${name}`);
325
325
  }
326
326
  // put to entries first, sort and then...
327
327
  let entries: Array<[CalcitTag, CalcitValue]> = [];
@@ -344,7 +344,7 @@ const extract_cirru_edn_inner = (x: CirruEdnFormat, options: CalcitValue, preser
344
344
  throw new Error(`Expected pair of size 2, got: ${pair}`);
345
345
  }
346
346
  } else {
347
- throw new Error(`Expected pairs for record, got: ${pair}`);
347
+ throw new Error(`Expected field pairs for struct, got: ${pair}`);
348
348
  }
349
349
  });
350
350
  entries.sort((a, b) => {
@@ -360,14 +360,14 @@ const extract_cirru_edn_inner = (x: CirruEdnFormat, options: CalcitValue, preser
360
360
 
361
361
  if (options instanceof CalcitMap || options instanceof CalcitSliceMap) {
362
362
  let v = options.get(extractFieldTag(name));
363
- if (v != null && v instanceof CalcitRecord) {
363
+ if (v != null && v instanceof CalcitStructValue) {
364
364
  if (deepEqual(v.fields, fields)) {
365
- return new CalcitRecord(extractFieldTag(name), fields, values, v.structRef);
365
+ return new CalcitStructValue(extractFieldTag(name), fields, values, v.structRef);
366
366
  }
367
367
  }
368
368
  }
369
369
 
370
- return new CalcitRecord(extractFieldTag(name), fields, values);
370
+ return new CalcitStructValue(extractFieldTag(name), fields, values);
371
371
  }
372
372
  let notComment = (x: any) => {
373
373
  if (x instanceof Array && x[0] === ";") {
@@ -402,9 +402,9 @@ const extract_cirru_edn_inner = (x: CirruEdnFormat, options: CalcitValue, preser
402
402
  }
403
403
  if (x[0] === "::") {
404
404
  if (x.length < 2) {
405
- throw new Error(`tuple expects at least 1 value, got: ${x}`);
405
+ throw new Error(`anonymous enum expects at least 1 value, got: ${x}`);
406
406
  }
407
- return new CalcitTuple(
407
+ return new CalcitEnumValue(
408
408
  extract_cirru_edn_inner(x[1], options, preserveSourceEntries),
409
409
  x
410
410
  .slice(2)
@@ -424,7 +424,7 @@ const extract_cirru_edn_inner = (x: CirruEdnFormat, options: CalcitValue, preser
424
424
  // unwrap prototype to record then extract name
425
425
  const proto = enumPrototype != null ? unwrap_enum_prototype_local(enumPrototype) : null;
426
426
  const enumTag = proto != null ? proto.name.toString() : enumName;
427
- return new CalcitTuple(
427
+ return new CalcitEnumValue(
428
428
  extract_cirru_edn_inner(x[2], options, preserveSourceEntries),
429
429
  x
430
430
  .slice(3)
@@ -505,12 +505,12 @@ export let to_calcit_data = (x: any, noKeyword: boolean = false): CalcitValue =>
505
505
  if (x instanceof CalcitList || x instanceof CalcitSliceList) return x;
506
506
  if (x instanceof CalcitMap || x instanceof CalcitSliceMap) return x;
507
507
  if (x instanceof CalcitSet) return x;
508
- if (x instanceof CalcitRecord) return x;
508
+ if (x instanceof CalcitStructValue) return x;
509
509
  if (x instanceof CalcitRecur) return x;
510
510
  if (x instanceof CalcitRef) return x;
511
511
  if (x instanceof CalcitTag) return x;
512
512
  if (x instanceof CalcitSymbol) return x;
513
- if (x instanceof CalcitTuple) return x;
513
+ if (x instanceof CalcitEnumValue) return x;
514
514
 
515
515
  // detects object
516
516
  if (x === Object(x)) {
@@ -1,11 +1,11 @@
1
- import { CalcitRecord } from "./js-record.mjs";
1
+ import { CalcitStructValue } from "./js-struct-value.mjs";
2
2
  import { CalcitImpl } from "./js-impl.mjs";
3
3
 
4
- export class CalcitEnum {
5
- prototype: CalcitRecord;
4
+ export class CalcitEnumDef {
5
+ prototype: CalcitStructValue;
6
6
  cachedHash: number;
7
7
 
8
- constructor(prototype: CalcitRecord) {
8
+ constructor(prototype: CalcitStructValue) {
9
9
  this.prototype = prototype;
10
10
  this.cachedHash = null;
11
11
  }
@@ -18,7 +18,7 @@ export class CalcitEnum {
18
18
  return this.prototype.structRef.impls;
19
19
  }
20
20
 
21
- withImpls(impls: CalcitImpl | CalcitImpl[]): CalcitEnum {
21
+ withImpls(impls: CalcitImpl | CalcitImpl[]): CalcitEnumDef {
22
22
  let nextImpls: CalcitImpl[];
23
23
  if (impls instanceof CalcitImpl) {
24
24
  nextImpls = [impls];
@@ -27,10 +27,10 @@ export class CalcitEnum {
27
27
  } else {
28
28
  throw new Error("Expected an impl as implementation");
29
29
  }
30
- return new CalcitEnum(this.prototype.withImpls(nextImpls));
30
+ return new CalcitEnumDef(this.prototype.withImpls(nextImpls));
31
31
  }
32
32
 
33
33
  toString(): string {
34
- return `(%enum :${this.prototype.name.value})`;
34
+ return `(%enum-def '${this.prototype.name.value})`;
35
35
  }
36
36
  }
@@ -3,15 +3,14 @@ import { Hash } from "@calcit/ternary-tree";
3
3
  import { CalcitValue } from "./js-primes.mjs";
4
4
  import { _$n__$e_, newTag, toString } from "./calcit-data.mjs";
5
5
  import { CalcitImpl } from "./js-impl.mjs";
6
- import { CalcitRecord } from "./js-record.mjs";
7
- import { CalcitEnum } from "./js-enum.mjs";
6
+ import { CalcitEnumDef } from "./js-enum-def.mjs";
8
7
 
9
- export class CalcitTuple {
8
+ export class CalcitEnumValue {
10
9
  tag: CalcitValue;
11
10
  extra: CalcitValue[];
12
- enumPrototype: CalcitRecord | CalcitEnum;
11
+ enumPrototype: CalcitEnumDef;
13
12
  cachedHash: Hash;
14
- constructor(tagName: CalcitValue, extra: CalcitValue[], enumPrototype: CalcitRecord | CalcitEnum = null) {
13
+ constructor(tagName: CalcitValue, extra: CalcitValue[], enumPrototype: CalcitEnumDef = null) {
15
14
  this.tag = tagName;
16
15
  this.extra = extra;
17
16
  this.enumPrototype = enumPrototype;
@@ -22,10 +21,7 @@ export class CalcitTuple {
22
21
  if (this.enumPrototype == null) {
23
22
  return [];
24
23
  }
25
- if (this.enumPrototype instanceof CalcitEnum) {
26
- return this.enumPrototype.impls;
27
- }
28
- return this.enumPrototype.structRef.impls;
24
+ return this.enumPrototype.impls;
29
25
  }
30
26
 
31
27
  get(n: number) {
@@ -34,24 +30,24 @@ export class CalcitTuple {
34
30
  } else if (n - 1 < this.extra.length) {
35
31
  return this.extra[n - 1];
36
32
  } else {
37
- throw new Error(`Tuple only have ${this.extra.length + 1} elements`);
33
+ throw new Error(`Enum value only has ${this.extra.length + 1} elements`);
38
34
  }
39
35
  }
40
36
  assoc(n: number, v: CalcitValue) {
41
37
  if (n === 0) {
42
- return new CalcitTuple(v, this.extra, this.enumPrototype);
38
+ return new CalcitEnumValue(v, this.extra, this.enumPrototype);
43
39
  } else if (n - 1 < this.extra.length) {
44
40
  let next_extra = this.extra.slice();
45
41
  next_extra[n - 1] = v;
46
- return new CalcitTuple(this.tag, next_extra, this.enumPrototype);
42
+ return new CalcitEnumValue(this.tag, next_extra, this.enumPrototype);
47
43
  } else {
48
- throw new Error(`Tuple only have ${this.extra.length} elements`);
44
+ throw new Error(`Enum value only has ${this.extra.length} elements`);
49
45
  }
50
46
  }
51
47
  count() {
52
48
  return 1 + this.extra.length;
53
49
  }
54
- eq(y: CalcitTuple): boolean {
50
+ eq(y: CalcitEnumValue): boolean {
55
51
  if (!_$n__$e_(this.tag, y.tag)) {
56
52
  return false;
57
53
  }
@@ -75,11 +71,8 @@ export class CalcitTuple {
75
71
  content += toString(args[i], true, disableJsDataWarning);
76
72
  }
77
73
  const hasEnum = this.enumPrototype != null;
78
- const enumName = hasEnum ? (this.enumPrototype instanceof CalcitEnum ? this.enumPrototype.prototype.name.value : this.enumPrototype.name.value) : null;
74
+ const enumName = hasEnum ? this.enumPrototype.name() : null;
79
75
 
80
- if (hasEnum) {
81
- return `(%:: ${content} (:enum ${enumName}))`;
82
- }
83
- return `(:: ${content})`;
76
+ return `(%:: ${hasEnum ? `'${enumName}` : "_"} ${content})`;
84
77
  }
85
78
  }
@@ -18,7 +18,7 @@ import {
18
18
 
19
19
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
20
20
  import { CalcitSet } from "./js-set.mjs";
21
- import { CalcitTuple } from "./js-tuple.mjs";
21
+ import { CalcitEnumValue } from "./js-enum-value.mjs";
22
22
 
23
23
  import { isNestedCalcitData, tipNestedCalcitData, toString, CalcitFn } from "./calcit-data.mjs";
24
24
 
@@ -349,7 +349,7 @@ export let foldl_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
349
349
  for (let idx = 0; idx < size; idx++) {
350
350
  let item = xs.get(idx);
351
351
  let pair = f(state, item);
352
- if (pair instanceof CalcitTuple) {
352
+ if (pair instanceof CalcitEnumValue) {
353
353
  if (typeof pair.tag === "boolean") {
354
354
  if (pair.tag) {
355
355
  return pair.get(1);
@@ -369,7 +369,7 @@ export let foldl_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
369
369
  for (let idx = 0; idx < values.length; idx++) {
370
370
  let item = values[idx];
371
371
  let pair = f(state, item);
372
- if (pair instanceof CalcitTuple) {
372
+ if (pair instanceof CalcitEnumValue) {
373
373
  if (typeof pair.tag === "boolean") {
374
374
  if (pair.tag) {
375
375
  return pair.get(1);
@@ -390,7 +390,7 @@ export let foldl_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
390
390
  for (let i = 0; i < size; i++) {
391
391
  let pos = i << 1;
392
392
  let pair = f(state, new CalcitSliceList([xs.chunk[pos], xs.chunk[pos + 1]]));
393
- if (pair instanceof CalcitTuple) {
393
+ if (pair instanceof CalcitEnumValue) {
394
394
  if (typeof pair.tag === "boolean") {
395
395
  if (pair.tag) {
396
396
  return pair.get(1);
@@ -410,7 +410,7 @@ export let foldl_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
410
410
  for (let idx = 0; idx < pairs.length; idx++) {
411
411
  let item = pairs[idx];
412
412
  let pair = f(state, new CalcitSliceList(item));
413
- if (pair instanceof CalcitTuple) {
413
+ if (pair instanceof CalcitEnumValue) {
414
414
  if (typeof pair.tag === "boolean") {
415
415
  if (pair.tag) {
416
416
  return pair.get(1);
@@ -440,7 +440,7 @@ export let foldr_shortcut = function (xs: CalcitValue, acc: CalcitValue, v0: Cal
440
440
  for (let idx = xs.len() - 1; idx >= 0; idx--) {
441
441
  let item = xs.get(idx);
442
442
  let pair = f(state, item);
443
- if (pair instanceof CalcitTuple) {
443
+ if (pair instanceof CalcitEnumValue) {
444
444
  if (typeof pair.tag === "boolean") {
445
445
  if (pair.tag) {
446
446
  return pair.get(1);
@@ -1,13 +1,13 @@
1
1
  import { CalcitTag, CalcitSymbol, CalcitFn, CalcitRecur } from "./calcit-data.mjs";
2
2
  import { CalcitRef } from "./js-ref.mjs";
3
3
  import { CalcitList, CalcitSliceList } from "./js-list.mjs";
4
- import { CalcitRecord } from "./js-record.mjs";
4
+ import { CalcitStructValue } from "./js-struct-value.mjs";
5
5
  import { CalcitImpl } from "./js-impl.mjs";
6
- import { CalcitStruct } from "./js-struct.mjs";
7
- import { CalcitEnum } from "./js-enum.mjs";
6
+ import { CalcitStructDef } from "./js-struct-def.mjs";
7
+ import { CalcitEnumDef } from "./js-enum-def.mjs";
8
8
  import { CalcitMap, CalcitSliceMap } from "./js-map.mjs";
9
9
  import { CalcitSet as CalcitSet } from "./js-set.mjs";
10
- import { CalcitTuple } from "./js-tuple.mjs";
10
+ import { CalcitEnumValue } from "./js-enum-value.mjs";
11
11
  import { CalcitCirruQuote, cirru_deep_equal } from "./js-cirru.mjs";
12
12
  import { CalcitTrait } from "./js-trait.mjs";
13
13
 
@@ -23,14 +23,14 @@ export type CalcitValue =
23
23
  | CalcitTag
24
24
  | CalcitSymbol
25
25
  | CalcitRef
26
- | CalcitTuple
26
+ | CalcitEnumValue
27
27
  | CalcitFn
28
28
  | CalcitRecur // should not be exposed to function
29
- | CalcitRecord
29
+ | CalcitStructValue
30
30
  | CalcitImpl
31
31
  | CalcitTrait
32
- | CalcitStruct
33
- | CalcitEnum
32
+ | CalcitStructDef
33
+ | CalcitEnumDef
34
34
  | CalcitCirruQuote
35
35
  | null;
36
36
 
@@ -52,15 +52,15 @@ enum PseudoTypeIndex {
52
52
  tag,
53
53
  string,
54
54
  ref,
55
- tuple,
55
+ enum_value,
56
56
  recur,
57
57
  list,
58
58
  set,
59
59
  map,
60
- record,
60
+ struct_value,
61
61
  impl,
62
- struct,
63
- enum_type,
62
+ struct_def,
63
+ enum_def,
64
64
  fn,
65
65
  cirru_quote,
66
66
  }
@@ -75,15 +75,15 @@ let typeAsInt = (x: CalcitValue): number => {
75
75
  if (x instanceof CalcitTag) return PseudoTypeIndex.tag;
76
76
  if (t === "string") return PseudoTypeIndex.string;
77
77
  if (x instanceof CalcitRef) return PseudoTypeIndex.ref;
78
- if (x instanceof CalcitTuple) return PseudoTypeIndex.tuple;
78
+ if (x instanceof CalcitEnumValue) return PseudoTypeIndex.enum_value;
79
79
  if (x instanceof CalcitRecur) return PseudoTypeIndex.recur;
80
80
  if (x instanceof CalcitList || x instanceof CalcitSliceList) return PseudoTypeIndex.list;
81
81
  if (x instanceof CalcitSet) return PseudoTypeIndex.set;
82
82
  if (x instanceof CalcitMap || x instanceof CalcitSliceMap) return PseudoTypeIndex.map;
83
- if (x instanceof CalcitRecord) return PseudoTypeIndex.record;
83
+ if (x instanceof CalcitStructValue) return PseudoTypeIndex.struct_value;
84
84
  if (x instanceof CalcitImpl) return PseudoTypeIndex.impl;
85
- if (x instanceof CalcitStruct) return PseudoTypeIndex.struct;
86
- if (x instanceof CalcitEnum) return PseudoTypeIndex.enum_type;
85
+ if (x instanceof CalcitStructDef) return PseudoTypeIndex.struct_def;
86
+ if (x instanceof CalcitEnumDef) return PseudoTypeIndex.enum_def;
87
87
  if (x instanceof CalcitCirruQuote) return PseudoTypeIndex.cirru_quote;
88
88
  // proc, fn, macro, syntax, not distinguished
89
89
  if (t === "function") return PseudoTypeIndex.fn;
@@ -2,7 +2,7 @@ import { CalcitTag, toString } from "./calcit-data.mjs";
2
2
  import { CalcitValue } from "./js-primes.mjs";
3
3
  import { CalcitImpl } from "./js-impl.mjs";
4
4
 
5
- export class CalcitStruct {
5
+ export class CalcitStructDef {
6
6
  name: CalcitTag;
7
7
  fields: CalcitTag[];
8
8
  fieldTypes: CalcitValue[];
@@ -11,7 +11,7 @@ export class CalcitStruct {
11
11
 
12
12
  constructor(name: CalcitTag, fields: CalcitTag[], fieldTypes: CalcitValue[], impls: CalcitImpl[] = []) {
13
13
  if (fields.length !== fieldTypes.length) {
14
- throw new Error("CalcitStruct: fields and fieldTypes length mismatch");
14
+ throw new Error("CalcitStructDef: fields and fieldTypes length mismatch");
15
15
  }
16
16
  this.name = name;
17
17
  this.fields = fields;
@@ -20,20 +20,20 @@ export class CalcitStruct {
20
20
  this.cachedHash = null;
21
21
  }
22
22
 
23
- withImpls(impls: CalcitImpl | CalcitImpl[]): CalcitStruct {
23
+ withImpls(impls: CalcitImpl | CalcitImpl[]): CalcitStructDef {
24
24
  if (impls instanceof CalcitImpl) {
25
- return new CalcitStruct(this.name, this.fields, this.fieldTypes, [impls]);
25
+ return new CalcitStructDef(this.name, this.fields, this.fieldTypes, [impls]);
26
26
  } else if (Array.isArray(impls)) {
27
- return new CalcitStruct(this.name, this.fields, this.fieldTypes, impls);
27
+ return new CalcitStructDef(this.name, this.fields, this.fieldTypes, impls);
28
28
  }
29
29
  throw new Error("Expected an impl as implementation");
30
30
  }
31
31
 
32
32
  toString(disableJsDataWarning: boolean = false): string {
33
33
  if (this.fields.length !== this.fieldTypes.length) {
34
- throw new Error("CalcitStruct: fields and fieldTypes length mismatch");
34
+ throw new Error("CalcitStructDef: fields and fieldTypes length mismatch");
35
35
  }
36
- const parts: string[] = ["(%struct :", this.name.value];
36
+ const parts: string[] = ["(%struct-def '", this.name.value];
37
37
  for (let idx = 0; idx < this.fields.length; idx++) {
38
38
  const field = this.fields[idx];
39
39
  const fieldType = this.fieldTypes[idx];