@calcit/procs 0.29.0-alpha.8 → 0.29.0

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.
@@ -37,6 +37,7 @@ export declare let newTag: (content: string) => CalcitTag;
37
37
  export declare let castTag: (x: CalcitValue) => CalcitTag;
38
38
  export declare var refsRegistry: Map<string, CalcitRef>;
39
39
  export declare let hashFunction: (x: CalcitValue) => Hash;
40
+ export declare let format_calcit_number: (x: number) => string;
40
41
  export declare let toString: (x: CalcitValue, escaped: boolean, disableJsDataWarning?: boolean) => string;
41
42
  export declare let to_js_data: (x: CalcitValue, options?: CalcitValue) => any;
42
43
  export declare let _$n_map_$o_get: (xs: CalcitValue, k: CalcitValue) => CalcitValue;
@@ -208,6 +208,7 @@ export var refsRegistry = new Map();
208
208
  let defaultHash_nil = valueHash("nil:");
209
209
  let defaultHash_unit = valueHash("unit:");
210
210
  let defaultHash_number = valueHash("number:");
211
+ let defaultHash_nan = valueHash("number:NaN");
211
212
  let defaultHash_string = valueHash("string:");
212
213
  let defaultHash_tag = valueHash("tag:");
213
214
  let defaultHash_true = valueHash("bool:true");
@@ -237,7 +238,10 @@ export let hashFunction = (x) => {
237
238
  if (x === undefined)
238
239
  return defaultHash_unit;
239
240
  if (typeof x === "number") {
240
- return mergeValueHash(defaultHash_number, x);
241
+ // NaN equals NaN, so it needs a hash that equals itself; `0` and `-0` share one hash
242
+ if (Number.isNaN(x))
243
+ return defaultHash_nan;
244
+ return mergeValueHash(defaultHash_number, x === 0 ? 0 : x);
241
245
  }
242
246
  if (typeof x === "string") {
243
247
  return mergeValueHash(defaultHash_string, x);
@@ -369,7 +373,8 @@ export let hashFunction = (x) => {
369
373
  let base = defaultHash_impl;
370
374
  base = mergeValueHash(base, hashFunction(x.name));
371
375
  if (x.origin != null) {
372
- base = mergeValueHash(base, hashFunction(x.origin));
376
+ // Impl equality compares origin names, not trait object identities.
377
+ base = mergeValueHash(base, hashFunction(x.origin.name.value));
373
378
  }
374
379
  for (let idx = 0; idx < x.fields.length; idx++) {
375
380
  base = mergeValueHash(base, hashFunction(x.fields[idx]));
@@ -442,6 +447,38 @@ let hashCirru = (base, x) => {
442
447
  };
443
448
  // Dirty code to change ternary-tree behavior
444
449
  overwriteHashGenerator(hashFunction);
450
+ // Calcit number text, shared by `turn-string`, `str` and printing (see docs/data/number.md).
451
+ export let format_calcit_number = (x) => {
452
+ // Match native f64 Display, which expands finite exponents into decimal notation.
453
+ if (Object.is(x, -0)) {
454
+ return "-0";
455
+ }
456
+ if (x === Infinity) {
457
+ return "inf";
458
+ }
459
+ if (x === -Infinity) {
460
+ return "-inf";
461
+ }
462
+ const text = x.toString();
463
+ const exponentIndex = text.indexOf("e");
464
+ if (exponentIndex < 0) {
465
+ return text;
466
+ }
467
+ const mantissa = text.slice(0, exponentIndex);
468
+ const exponent = Number(text.slice(exponentIndex + 1));
469
+ const sign = mantissa.startsWith("-") ? "-" : "";
470
+ const unsigned = sign ? mantissa.slice(1) : mantissa;
471
+ const decimalPoint = unsigned.indexOf(".");
472
+ const decimalIndex = (decimalPoint < 0 ? unsigned.length : decimalPoint) + exponent;
473
+ const digits = unsigned.replace(".", "");
474
+ if (decimalIndex <= 0) {
475
+ return `${sign}0.${"0".repeat(-decimalIndex)}${digits}`;
476
+ }
477
+ if (decimalIndex >= digits.length) {
478
+ return `${sign}${digits}${"0".repeat(decimalIndex - digits.length)}`;
479
+ }
480
+ return `${sign}${digits.slice(0, decimalIndex)}.${digits.slice(decimalIndex)}`;
481
+ };
445
482
  export let toString = (x, escaped, disableJsDataWarning = false) => {
446
483
  if (x === null) {
447
484
  return "nil";
@@ -463,7 +500,7 @@ export let toString = (x, escaped, disableJsDataWarning = false) => {
463
500
  }
464
501
  }
465
502
  if (typeof x === "number") {
466
- return x.toString();
503
+ return format_calcit_number(x);
467
504
  }
468
505
  if (typeof x === "boolean") {
469
506
  return x.toString();
@@ -656,8 +693,8 @@ export let _$n__$e_ = (x, y) => {
656
693
  return false;
657
694
  }
658
695
  if (tx === "number") {
659
- // already checked above
660
- return false;
696
+ // value equality: NaN equals NaN (`0 === -0` already held above)
697
+ return Number.isNaN(x) && Number.isNaN(y);
661
698
  }
662
699
  if (tx === "function") {
663
700
  // method values are closures created on the fly (see invoke_method_closure),
@@ -837,7 +874,11 @@ export let _$n__$e_ = (x, y) => {
837
874
  }
838
875
  if (x instanceof CalcitEnumDef) {
839
876
  if (y instanceof CalcitEnumDef) {
840
- return x.name === y.name;
877
+ // The prototype carries the nominal origin, variant tags and payload
878
+ // schemas. Comparing name methods compares one shared function object.
879
+ return _$n__$e_(x.prototype, y.prototype)
880
+ && x.impls.length === y.impls.length
881
+ && x.impls.every((impl, index) => _$n__$e_(impl, y.impls[index]));
841
882
  }
842
883
  return false;
843
884
  }
@@ -31,6 +31,7 @@ export declare const calcit_package_json: {
31
31
  "check-smooth": string;
32
32
  "check-all": string;
33
33
  "check-strict-default": string;
34
+ "check-core-tests": string;
34
35
  "check-agent-interface": string;
35
36
  "try-all": string;
36
37
  "try-core-tests": string;
@@ -111,7 +112,7 @@ export declare let _$L_: (...xs: CalcitValue[]) => CalcitSliceList;
111
112
  export declare let _SQUO_: (...xs: CalcitValue[]) => CalcitSliceList;
112
113
  export declare let _$n__$M_: (...xs: CalcitValue[]) => CalcitSliceMap;
113
114
  export declare let defatom: (path: string, x: CalcitValue) => CalcitValue;
114
- export { atom } from "./js-ref.mjs";
115
+ export { atom, ref } from "./js-ref.mjs";
115
116
  export declare let peekDefatom: (path: string) => CalcitRef;
116
117
  export declare let _$n_atom_$o_deref: (x: CalcitRef) => CalcitValue;
117
118
  export declare let _$n__ADD_: (x: number, y: number) => number;
@@ -154,7 +155,7 @@ export declare let _$n_list_$o_assoc_after: (xs: CalcitSliceList, k: number, v:
154
155
  export declare let _$n_list_$o_dissoc: (xs: CalcitValue | CalcitSliceList, k: CalcitValue) => CalcitList | CalcitSliceList;
155
156
  export declare let _$n_map_$o_dissoc: (xs: CalcitValue, ...args: CalcitValue[]) => CalcitMap | CalcitSliceMap;
156
157
  export declare let reset_$x_: (a: CalcitRef, v: CalcitValue) => CalcitValue;
157
- export declare let add_watch: (a: CalcitRef, k: CalcitTag, f: CalcitFn) => void;
158
+ export declare let add_watch_$x_: (a: CalcitRef, k: CalcitTag, f: CalcitFn) => void;
158
159
  export declare let remove_watch: (a: CalcitRef, k: CalcitTag) => void;
159
160
  export declare let range: (n: number, m?: number, step?: number) => CalcitSliceList;
160
161
  export declare function _$n_list_$o_empty_$q_(xs: CalcitValue): boolean;
@@ -188,7 +189,8 @@ export declare let _$n__GT_: (a: number, b: number) => boolean;
188
189
  export declare let _$n__LT_: (a: number, b: number) => boolean;
189
190
  export declare let _$n__: (a: number, b: number) => number;
190
191
  export declare let _$n__SLSH_: (a: number, b: number) => number;
191
- /** Truncated remainder over safe integers, matching native and WASM; the result is never `-0`. */
192
+ /** Truncated remainder over safe integers, matching native and WASM; the result is never `-0`.
193
+ * Operands in the error use the native number text (`inf`, expanded exponents) so messages match native. */
192
194
  export declare let _$n_number_$o_rem: (a: number, b: number) => number;
193
195
  export declare let _$n_number_$o_fits_$q_: (value: number, target: CalcitTag) => boolean;
194
196
  export declare let round_$q_: (a: number) => boolean;
@@ -241,7 +243,7 @@ export declare let turn_symbol: (x: CalcitValue) => CalcitSymbol;
241
243
  export declare let to_lispy_string: (...args: CalcitValue[]) => string;
242
244
  /** helper function for println, js only */
243
245
  export declare let printable: (...args: CalcitValue[]) => string;
244
- export declare let cpu_time: () => number;
246
+ export declare let monotonic_time_ms: () => number;
245
247
  export declare let quit_$x_: (code: number) => void;
246
248
  export declare let turn_string: (x: CalcitValue) => string;
247
249
  export declare let identical_$q_: (x: CalcitValue, y: CalcitValue) => boolean;
@@ -323,6 +325,8 @@ type DataShapeGraph = {
323
325
  fingerprint: string;
324
326
  nodes: DataShapeNode[];
325
327
  };
328
+ /** Validate existing data without the decoder's map conversion or Option lifting. */
329
+ export declare function validate_data_shape(input: CalcitValue, graph: DataShapeGraph): boolean;
326
330
  export declare let parse_cirru_edn_as: (code: string, graph: DataShapeGraph) => CalcitValue;
327
331
  export declare let decode_map_as: (value: CalcitValue, graph: DataShapeGraph) => CalcitValue;
328
332
  export declare let json_parse: (code: CalcitValue) => CalcitValue;
@@ -361,6 +365,7 @@ export declare function _$n_methods_of(obj: CalcitValue): CalcitSliceList;
361
365
  export declare function _$n_inspect_methods(obj: CalcitValue, note: CalcitValue): CalcitValue;
362
366
  /** Dispatch through one nominal origin; duplicate implementations never select by order. */
363
367
  export declare function _$n_trait_call(traitDef: CalcitValue, method: CalcitValue, obj: CalcitValue, ...args: CalcitValue[]): CalcitValue;
368
+ export declare let _$n_map_$o_fold_kv: (m: CalcitValue, initial: CalcitValue, reducer: CalcitFn) => CalcitValue;
364
369
  export declare let _$n_map_$o_to_list: (m: CalcitValue) => CalcitSliceList;
365
370
  export declare let _$n_map_$o_keys: (m: CalcitValue) => CalcitSet;
366
371
  export declare let _$n_map_$o_vals: (m: CalcitValue) => CalcitSliceList;
@@ -393,7 +398,7 @@ export declare let macroexpand_all: () => void;
393
398
  export declare let _$n_get_calcit_running_mode: () => void;
394
399
  export declare let _$n_get_def_doc: () => void;
395
400
  export declare let _$n_get_def_schema: () => void;
396
- export declare let _$n_ffi_response_resolve: () => void;
397
- export declare let _$n_ffi_response_reject: () => void;
398
- export declare let _$n_ffi_task_cancel: () => void;
401
+ export declare let _$n_ffi_response_resolve: (..._args: CalcitValue[]) => never;
402
+ export declare let _$n_ffi_response_reject: (..._args: CalcitValue[]) => never;
403
+ export declare let _$n_ffi_task_cancel: (..._args: CalcitValue[]) => never;
399
404
  export declare let raise: () => void;