@calcit/procs 0.6.27 → 0.6.28

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.
@@ -1,6 +1,6 @@
1
1
  var _a;
2
2
  // CALCIT VERSION
3
- export const calcit_version = "0.6.27";
3
+ export const calcit_version = "0.6.28";
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";
@@ -244,6 +244,13 @@ export let _$n_tuple_$o_nth = function (xs, k) {
244
244
  return xs.get(k);
245
245
  throw new Error("Does not support `nth` on this type");
246
246
  };
247
+ export let _$n_tuple_$o_count = function (xs) {
248
+ if (arguments.length !== 1)
249
+ throw new Error("&tuple:count takes 1 arguments");
250
+ if (xs instanceof CalcitTuple)
251
+ return xs.count();
252
+ throw new Error("Does not support `count` on this type");
253
+ };
247
254
  export let _$n_record_$o_get = function (xs, k) {
248
255
  if (arguments.length !== 2) {
249
256
  throw new Error("record &get takes 2 arguments");
@@ -1154,8 +1161,8 @@ export let _$n_js_object = (...xs) => {
1154
1161
  }
1155
1162
  return ret;
1156
1163
  };
1157
- export let _$o__$o_ = (a, b) => {
1158
- return new CalcitTuple(a, b);
1164
+ export let _$o__$o_ = (a, b, ...extra) => {
1165
+ return new CalcitTuple(a, b, extra);
1159
1166
  };
1160
1167
  // mutable place for core to register
1161
1168
  let calcit_builtin_classes = {
package/lib/js-cirru.mjs CHANGED
@@ -245,10 +245,10 @@ export let extract_cirru_edn = (x) => {
245
245
  return new CalcitCirruQuote(x[1]);
246
246
  }
247
247
  if (x[0] === "::") {
248
- if (x.length !== 3) {
249
- throw new Error("tuple expects 2 values");
248
+ if (x.length < 3) {
249
+ throw new Error("tuple expects at least 2 values");
250
250
  }
251
- return new CalcitTuple(extract_cirru_edn(x[1]), extract_cirru_edn(x[2]));
251
+ return new CalcitTuple(extract_cirru_edn(x[1]), extract_cirru_edn(x[2]), x.slice(3).map(extract_cirru_edn));
252
252
  }
253
253
  }
254
254
  console.error(x);
package/lib/js-tuple.mjs CHANGED
@@ -1,8 +1,9 @@
1
1
  import { toString } from "./calcit-data.mjs";
2
2
  export class CalcitTuple {
3
- constructor(a, b) {
3
+ constructor(a, b, extra) {
4
4
  this.fst = a;
5
5
  this.snd = b;
6
+ this.extra = extra;
6
7
  this.cachedHash = null;
7
8
  }
8
9
  get(n) {
@@ -12,21 +13,32 @@ export class CalcitTuple {
12
13
  else if (n === 1) {
13
14
  return this.snd;
14
15
  }
16
+ else if (n - 2 < this.extra.length) {
17
+ return this.extra[n - 2];
18
+ }
15
19
  else {
16
20
  throw new Error("Tuple only have 2 elements");
17
21
  }
18
22
  }
19
23
  assoc(n, v) {
20
24
  if (n === 0) {
21
- return new CalcitTuple(v, this.snd);
25
+ return new CalcitTuple(v, this.snd, this.extra);
22
26
  }
23
27
  else if (n === 1) {
24
- return new CalcitTuple(this.fst, v);
28
+ return new CalcitTuple(this.fst, v, this.extra);
29
+ }
30
+ else if (n - 2 < this.extra.length) {
31
+ let next_extra = this.extra.slice();
32
+ next_extra[n - 2] = v;
33
+ return new CalcitTuple(this.fst, this.snd, next_extra);
25
34
  }
26
35
  else {
27
36
  throw new Error("Tuple only have 2 elements");
28
37
  }
29
38
  }
39
+ count() {
40
+ return 2 + this.extra.length;
41
+ }
30
42
  toString(disableJsDataWarning = false) {
31
43
  return `(&tuple ${toString(this.fst, false, disableJsDataWarning)} ${toString(this.snd, false, disableJsDataWarning)})`;
32
44
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.6.27",
3
+ "version": "0.6.28",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "devDependencies": {
6
- "@types/node": "^18.16.3",
6
+ "@types/node": "^20.2.3",
7
7
  "typescript": "^5.0.4"
8
8
  },
9
9
  "scripts": {
@@ -1,5 +1,5 @@
1
1
  // CALCIT VERSION
2
- export const calcit_version = "0.6.27";
2
+ export const calcit_version = "0.6.28";
3
3
 
4
4
  import { parse, ICirruNode } from "@cirru/parser.ts";
5
5
  import { writeCirruCode } from "@cirru/writer.ts";
@@ -290,6 +290,13 @@ export let _$n_tuple_$o_nth = function (xs: CalcitValue, k: CalcitValue) {
290
290
 
291
291
  throw new Error("Does not support `nth` on this type");
292
292
  };
293
+ export let _$n_tuple_$o_count = function (xs: CalcitValue) {
294
+ if (arguments.length !== 1) throw new Error("&tuple:count takes 1 arguments");
295
+
296
+ if (xs instanceof CalcitTuple) return xs.count();
297
+
298
+ throw new Error("Does not support `count` on this type");
299
+ };
293
300
 
294
301
  export let _$n_record_$o_get = function (xs: CalcitValue, k: CalcitKeyword) {
295
302
  if (arguments.length !== 2) {
@@ -1253,8 +1260,8 @@ export let _$n_js_object = (...xs: CalcitValue[]): Record<string, CalcitValue> =
1253
1260
  return ret;
1254
1261
  };
1255
1262
 
1256
- export let _$o__$o_ = (a: CalcitValue, b: CalcitValue): CalcitTuple => {
1257
- return new CalcitTuple(a, b);
1263
+ export let _$o__$o_ = (a: CalcitValue, b: CalcitValue, ...extra: CalcitValue[]): CalcitTuple => {
1264
+ return new CalcitTuple(a, b, extra);
1258
1265
  };
1259
1266
 
1260
1267
  // mutable place for core to register
@@ -246,10 +246,10 @@ export let extract_cirru_edn = (x: CirruEdnFormat): CalcitValue => {
246
246
  return new CalcitCirruQuote(x[1]);
247
247
  }
248
248
  if (x[0] === "::") {
249
- if (x.length !== 3) {
250
- throw new Error("tuple expects 2 values");
249
+ if (x.length < 3) {
250
+ throw new Error("tuple expects at least 2 values");
251
251
  }
252
- return new CalcitTuple(extract_cirru_edn(x[1]), extract_cirru_edn(x[2]));
252
+ return new CalcitTuple(extract_cirru_edn(x[1]), extract_cirru_edn(x[2]), x.slice(3).map(extract_cirru_edn));
253
253
  }
254
254
  }
255
255
  console.error(x);
@@ -6,10 +6,12 @@ import { toString } from "./calcit-data.mjs";
6
6
  export class CalcitTuple {
7
7
  fst: CalcitValue;
8
8
  snd: CalcitValue;
9
+ extra: CalcitValue[];
9
10
  cachedHash: Hash;
10
- constructor(a: CalcitValue, b: CalcitValue) {
11
+ constructor(a: CalcitValue, b: CalcitValue, extra: CalcitValue[]) {
11
12
  this.fst = a;
12
13
  this.snd = b;
14
+ this.extra = extra;
13
15
  this.cachedHash = null;
14
16
  }
15
17
  get(n: number) {
@@ -17,19 +19,28 @@ export class CalcitTuple {
17
19
  return this.fst;
18
20
  } else if (n === 1) {
19
21
  return this.snd;
22
+ } else if (n - 2 < this.extra.length) {
23
+ return this.extra[n - 2];
20
24
  } else {
21
25
  throw new Error("Tuple only have 2 elements");
22
26
  }
23
27
  }
24
28
  assoc(n: number, v: CalcitValue) {
25
29
  if (n === 0) {
26
- return new CalcitTuple(v, this.snd);
30
+ return new CalcitTuple(v, this.snd, this.extra);
27
31
  } else if (n === 1) {
28
- return new CalcitTuple(this.fst, v);
32
+ return new CalcitTuple(this.fst, v, this.extra);
33
+ } else if (n - 2 < this.extra.length) {
34
+ let next_extra = this.extra.slice();
35
+ next_extra[n - 2] = v;
36
+ return new CalcitTuple(this.fst, this.snd, next_extra);
29
37
  } else {
30
38
  throw new Error("Tuple only have 2 elements");
31
39
  }
32
40
  }
41
+ count() {
42
+ return 2 + this.extra.length;
43
+ }
33
44
  toString(disableJsDataWarning: boolean = false): string {
34
45
  return `(&tuple ${toString(this.fst, false, disableJsDataWarning)} ${toString(this.snd, false, disableJsDataWarning)})`;
35
46
  }