@mark1russell7/vex 0.17.2 → 0.19.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.
package/build/index.d.ts CHANGED
@@ -1,4 +1,8 @@
1
- import { Agreement, Definitions, Envelope, Envelope as Envelope$1, EvalError, HostThing, Json, KernelCode, Machine, Result as Result$1, World } from "@mark1russell7/coeval";
1
+ /**
2
+ * The core of Vex: spaces, addresses, the expression IR and its documents, domains, the interpreter and its folds. It
3
+ * also has Vex in the kernel of coeval: the contracts of its kinds and the reference tier.
4
+ */
5
+ import { Agreement, Definitions, Envelope, Envelope as Envelope$1, EvalError, HostThing, Json, KernelCode, Machine, Result as Result$1, StepLadder, World } from "@mark1russell7/coeval";
2
6
  /**
3
7
  * The Optional of the family: a value that is present (`Some`) or absent (`None`). The packages render and Vex use
4
8
  * this form. Graph uses a sentinel form, and `fromSentinel` and `toSentinel` convert between the two forms.
@@ -105,6 +109,230 @@ export declare const getOr: <T, U>(o: Optional<T>, fallback: U) => T | U;
105
109
  export declare const mapResult: <T, U>(r: Result<T>, f: (value: T) => U) => Result<U>;
106
110
  /** This function applies `f` to the value of a `Result`, and `f` gives a `Result`. An error stays the same. */
107
111
  export declare const chainResult: <T, U>(r: Result<T>, f: (value: T) => Result<U>) => Result<U>;
112
+ /**
113
+ * Domains. A domain tells which values belong to it and which ops it has. The domain object owns this data.
114
+ * Vex does not write to the prototypes of domain classes, and an import has no side effects.
115
+ */
116
+ /** An algebraic law that an op claims. `@mark1russell7/vex-testkit` checks each claim with property tests. */
117
+ export type Law = "commutative" | "associative" | "idempotent";
118
+ /** The kind of a parameter. The interpreter checks the arguments of an op that declares its parameters. */
119
+ export type ParamKind = "domain" | "number" | "boolean" | "string" | "any";
120
+ /**
121
+ * The kind of the result of an op. It is a kind of a parameter, or `domain:Name` for a value of the domain `Name`. It is
122
+ * `list:Kind` for a `vex.list` with items of a primitive type.
123
+ */
124
+ export type ReturnKind = ParamKind | `domain:${string}` | `list:${PrimitiveKind}`;
125
+ /**
126
+ * How the size of one argument adds to the size of the result of an op (LOOP.SIZE.OPS). The size of a value counts the
127
+ * texts, the fields, the keys and the items in it.
128
+ *
129
+ * - `0`: the argument does not add to the size.
130
+ * - `1`: the size of the argument adds one time.
131
+ * - `"scaled"`: the size of the argument adds a fixed number of times, for example two times.
132
+ * - `"many"`: the size of the argument adds more than one time.
133
+ * - `"unbounded"`: the size of the result has no bound in the size of the argument.
134
+ * - `"text"`: the size adds one time for a text, and a fixed number of times for another value, as its JSON text.
135
+ * - `"copies"`: the size adds one time for each copy. The first argument is the number of the copies.
136
+ * - `"each"`: the size adds one time for each item of the first argument.
137
+ * - `"number"`: the argument is a number that sets a count. A literal number gives that count, and another number
138
+ * gives a fixed bound.
139
+ * - `"limit"`: the size adds one time for each item that the literal number at the position `limit` keeps. Each item
140
+ * adds a key with a fixed bound. Without a literal number, this use is the same as `"many"`.
141
+ */
142
+ export type SizeUse = 0 | 1 | "scaled" | "many" | "unbounded" | "text" | "copies" | "each" | "number" | "limit";
143
+ /**
144
+ * A measure of a value for the check of sizes (LOOP.SIZE.OPS). `size` is the size of the value, and `count` is the
145
+ * number of its items. `inner` is the sum of the counts of the values of its items. `item` is the size of its largest
146
+ * item. The items of a record are its fields, and a text is its own item. `part` is the largest `item` of its items. It is
147
+ * not larger than `item`.
148
+ */
149
+ export type SizeMeasure = "size" | "count" | "inner" | "item" | "part";
150
+ /** One term of a size rule: a use of the same measure of the argument, or a use of the measure that the pair names. */
151
+ export type SizeTerm = SizeUse | readonly [use: SizeUse, of: SizeMeasure];
152
+ /**
153
+ * The size rule of an op: how the measures of its result follow from its arguments (LOOP.SIZE.OPS). The check of sizes
154
+ * reads it in the steps of `fold` and `iterate` (LOOP.SIZE).
155
+ *
156
+ * - `"scalar"`: the result is a number or a boolean.
157
+ * - `"fixed"`: the result has a size with a fixed bound, for example a 2D vector.
158
+ * - `"reduce"`: the rule of the list op `reduce`. The op that its second argument names gives the size.
159
+ * - A record: `SizeTerms`.
160
+ */
161
+ export type SizeRule = "scalar" | "fixed" | "reduce" | SizeTerms;
162
+ /**
163
+ * The size rule of an op as data (LOOP.SIZE.OPS). `size`, `count`, `inner`, `item` and `part` have one term for each
164
+ * argument. `rest` is the use of the arguments after them, and its default is `"many"`. Without `count`, `inner` or `item`,
165
+ * that measure of the result is its size. Without `part`, the largest part of the result is its largest item. The terms of
166
+ * `item` and `part` give the largest bound of the arguments, because the largest item comes from one argument. A literal
167
+ * number at the position `limit` sets the count. With `keys: "position"`, the items get their positions as new keys. With
168
+ * `constant: true`, the result can also hold a part with a fixed size. With `union: true`, the result holds each key of
169
+ * its arguments one time, so the bound of the result is the largest bound of the arguments.
170
+ *
171
+ * `byParts` is a second rule for a result that is a part of an argument, or that holds a fixed number of its items. The
172
+ * second reading of the check uses this rule (LOOP.SIZE.READINGS). A rule with `limit` keeps the first rule when the limit
173
+ * is not a literal number or when a key can be long.
174
+ */
175
+ export interface SizeTerms {
176
+ readonly size: readonly SizeTerm[];
177
+ readonly count?: readonly SizeTerm[];
178
+ readonly inner?: readonly SizeTerm[];
179
+ readonly item?: readonly SizeTerm[];
180
+ readonly part?: readonly SizeTerm[];
181
+ readonly rest?: SizeUse;
182
+ readonly limit?: number;
183
+ readonly keys?: "position";
184
+ readonly constant?: true;
185
+ readonly union?: true;
186
+ readonly byParts?: SizeTerms;
187
+ }
188
+ /** The description of one op of a domain. */
189
+ export interface OpSpec<D = never> {
190
+ /**
191
+ * The implementation, for an op that is not a method of the value (static-land style). The first argument
192
+ * is the receiver. Without `fn`, the interpreter calls the method of the receiver with the same name.
193
+ */
194
+ readonly fn?: (self: D, ...args: never[]) => unknown;
195
+ /** The laws that the op claims. */
196
+ readonly laws?: readonly Law[];
197
+ /** The identity element of the op, for reductions over an empty list. */
198
+ readonly identity?: () => D;
199
+ /** Scalar lifting: `true` lifts each number argument with `fromScalar`. An array sets it for each argument. */
200
+ readonly liftScalar?: boolean | readonly boolean[];
201
+ /** The kinds of the parameters after the receiver. When set, the interpreter checks the arguments. */
202
+ readonly params?: readonly ParamKind[];
203
+ /**
204
+ * The kind of the result. It is `domain` for a value of this domain, or `domain:Name` for a value of the domain `Name`.
205
+ * It is `list:Kind` for a `vex.list` with items of that primitive type (KIND.RETURNS.LIST). A compiler reads it to know
206
+ * the kinds of the values of a program (KIND.RETURNS). The interpreter does not check it, and the law checker of the
207
+ * test kit does.
208
+ */
209
+ readonly returns?: ReturnKind;
210
+ /**
211
+ * The size rule of the op (LOOP.SIZE.OPS). Without it, an op whose result is a number or a boolean has the rule
212
+ * `"scalar"`. An op of a domain with `size: "fixed"` has the rule `"fixed"`. Another op has no rule, so a step of a
213
+ * loop cannot use its result in the size of a list name (LOOP.SIZE).
214
+ */
215
+ readonly size?: SizeRule;
216
+ /**
217
+ * This field gives the direction of the result of the op for each argument, with the receiver first (FIX.OPS). `up`
218
+ * means that the result does not fall as the argument rises. `down` means that the result does not rise. An op without
219
+ * it cannot take a value that reads `last`, and an argument without a direction must not read `last`.
220
+ */
221
+ readonly monotone?: readonly Monotone[];
222
+ }
223
+ /** A direction of an op: the result follows the argument (`up`) or moves against it (`down`). */
224
+ export type Monotone = "up" | "down";
225
+ /**
226
+ * The form of a domain in a standalone module (COMPILE.MODULE.FORM). A module has no import, so it cannot hold a value of
227
+ * a class. Each part replaces the part of the domain with the same name, only in a module. A compiler copies the text of
228
+ * each function, so a function reads only its parameters.
229
+ */
230
+ export interface ModuleForm {
231
+ /** The test of a value in a module. */
232
+ readonly is?: (u: unknown) => boolean;
233
+ /** The scalar lift in a module. */
234
+ readonly fromScalar?: (n: number) => unknown;
235
+ /** Some values of the module form. A compiler checks each copy with them. */
236
+ readonly samples?: () => readonly unknown[];
237
+ /**
238
+ * The plain data of a literal of the program, or `undefined` for a value of another domain. This function runs in the
239
+ * compiler, not in a module, so it can read a class.
240
+ */
241
+ readonly literal?: (value: unknown) => Readonly<Record<string, unknown>> | undefined;
242
+ /** The parts of each op in a module. */
243
+ readonly ops?: Readonly<Record<string, {
244
+ readonly fn?: (self: never, ...args: never[]) => unknown;
245
+ readonly identity?: () => unknown;
246
+ readonly returns?: ReturnKind;
247
+ }>>;
248
+ }
249
+ /** A JavaScript type of primitive values that a domain can accept. */
250
+ export type PrimitiveKind = "number" | "string" | "boolean";
251
+ /** This function gives the kind of the items of a result of the kind `list:Kind`, or `undefined` for another kind. */
252
+ export declare const listItemKind: (r: ReturnKind | undefined) => PrimitiveKind | undefined;
253
+ /** The type of an op that lifts number arguments. Use it to type the ops of a domain under `isolatedDeclarations`. */
254
+ export type LiftedOp<D> = OpSpec<D> & {
255
+ readonly liftScalar: true;
256
+ };
257
+ /** The type of an op with an implementation function `F`. */
258
+ export type FnOp<D, F extends (self: D, ...args: never[]) => unknown> = OpSpec<D> & {
259
+ readonly fn: F;
260
+ };
261
+ /**
262
+ * The type of an op table: each name in `Names` is an op, and each name in `Lifted` lifts number arguments.
263
+ * Use it to type the ops of a domain under `isolatedDeclarations`.
264
+ */
265
+ export type OpTable<D, Names extends string, Lifted extends string = never> = { readonly [N in Names]: N extends Lifted ? LiftedOp<D> : OpSpec<D>; };
266
+ /** The description of a domain, as a caller gives it to `defineDomain`. */
267
+ export interface DomainSpec<Name extends string, D, Ops extends Readonly<Record<string, OpSpec<D>>>> {
268
+ /** The name of the domain. */
269
+ readonly name: Name;
270
+ /** The runtime test for the values of the domain. It must not give false positives. */
271
+ readonly is: (u: unknown) => u is D;
272
+ /**
273
+ * The JavaScript type of the values of the domain, if `is` accepts each value of that type and no other value
274
+ * (KIND.PRIMITIVE). A compiler then finds the op of such a value before a run.
275
+ */
276
+ readonly primitive?: PrimitiveKind;
277
+ /**
278
+ * The field names of a value, if `is` accepts only plain objects with exactly these fields (KIND.FIELDS). Two domains
279
+ * with different names have no common value, so a compiler finds the domain of such a value before a run.
280
+ */
281
+ readonly fields?: readonly string[];
282
+ /** The ops of the domain, with their metadata. */
283
+ readonly ops: Ops;
284
+ /**
285
+ * With `"fixed"`, each value of the domain has a size with a fixed bound, for example a 2D vector. Then each op of the
286
+ * domain has the size rule `"fixed"` or `"scalar"`, unless the op has its own rule (LOOP.SIZE.OPS).
287
+ */
288
+ readonly size?: "fixed";
289
+ /** With `"all"`, each method of a value is an op, also without an entry in `ops`. The default is `"declared"`. */
290
+ readonly methods?: "declared" | "all";
291
+ /** The scalar lift: it makes a domain value from a number. */
292
+ readonly fromScalar?: (n: number) => D;
293
+ /** A check of the values that ops give. A value that fails the check gives the error `#NUM!`. */
294
+ readonly valid?: (d: D) => boolean;
295
+ /** A short text for a value, for traces and the site. */
296
+ readonly show?: (d: D) => string;
297
+ /** The JSON form of a value, for literals in serialized programs. */
298
+ readonly encode?: (d: D) => unknown;
299
+ /** The value of a JSON form that `encode` made. */
300
+ readonly decode?: (json: unknown) => D;
301
+ /**
302
+ * Some values of the domain. A compiler gives them to an op and to its copy in a module: the two must give the same
303
+ * results (KIND.DOMAIN).
304
+ */
305
+ readonly samples?: () => readonly D[];
306
+ /** The form of the domain in a standalone module, for a domain with values of a class (COMPILE.MODULE.FORM). */
307
+ readonly moduleForm?: ModuleForm;
308
+ }
309
+ /** A domain. Make one with `defineDomain`. */
310
+ export interface Domain<Name extends string = string, D = unknown, Ops extends Readonly<Record<string, OpSpec<D>>> = Readonly<Record<string, OpSpec<D>>>> extends DomainSpec<Name, D, Ops> {
311
+ readonly kind: "vex.domain";
312
+ }
313
+ /** A domain with any value type. The interpreter uses this type. */
314
+ export type AnyDomain = Domain<string, any, Readonly<Record<string, OpSpec<any>>>>;
315
+ /** This function makes a domain. The result is frozen. */
316
+ export declare function defineDomain<const Name extends string, D, const Ops extends Readonly<Record<string, OpSpec<D>>>>(spec: DomainSpec<Name, D, Ops>): Domain<Name, D, Ops>;
317
+ /** This function tells if a name can be an op name. */
318
+ export declare const isOpName: (name: string) => boolean;
319
+ /**
320
+ * This function finds a method on a value: an own function property, or a function on the prototype chain.
321
+ * It stops at `Object.prototype` and `Function.prototype`, so inherited members (for example `toString`) are not ops.
322
+ */
323
+ export declare function findMethod(self: unknown, name: string): ((...args: unknown[]) => unknown) | undefined;
324
+ /** An op that the interpreter found for a receiver. */
325
+ export interface ResolvedOp {
326
+ readonly domain: AnyDomain;
327
+ readonly spec: OpSpec<unknown>;
328
+ readonly call: (args: readonly unknown[]) => unknown;
329
+ }
330
+ /** This function finds the op `name` for `self` in one domain. It gives `undefined` if the domain does not have it. */
331
+ export declare function resolveOp(domain: AnyDomain, self: unknown, name: string): ResolvedOp | undefined;
332
+ /** This function gives the domain of a value: the first domain whose `is` accepts it. */
333
+ export declare function domainOf(domains: readonly AnyDomain[], value: unknown): AnyDomain | undefined;
334
+ /** This function tells if the `liftScalar` setting lifts the argument at `index`. */
335
+ export declare const liftsAt: (lift: OpSpec<unknown>["liftScalar"], index: number) => boolean;
108
336
  /**
109
337
  * One move of an address. The moves of an address apply in order, from the focus of the evaluation. The key of `key`
110
338
  * and the position of `index` can be an expression, which evaluates before the moves (NAV.COMPUTED).
@@ -217,11 +445,20 @@ export type Expr = {
217
445
  readonly as?: ItemNames;
218
446
  } | {
219
447
  readonly tag: "iterate";
220
- readonly limit: number;
448
+ readonly limit: number | DataLimit;
221
449
  readonly init: Names;
222
450
  readonly step: Names;
223
451
  readonly until?: Expr;
224
452
  readonly result: Expr;
453
+ } | {
454
+ readonly tag: "fix";
455
+ readonly name: string;
456
+ readonly join: FixJoin;
457
+ readonly init: Expr;
458
+ readonly step: Expr;
459
+ } | {
460
+ readonly tag: "last";
461
+ readonly name: string;
225
462
  } | {
226
463
  readonly tag: "fn";
227
464
  readonly params: readonly string[];
@@ -242,8 +479,17 @@ export type Names = Readonly<Record<string, Expr>>;
242
479
  * its position (AXIS.LIST.ITEM, AXIS.LIST.INDEX). The body of `each` and the steps of `fold` see them (AXIS.LIST.SCOPE).
243
480
  */
244
481
  export type ItemNames = readonly [item: string] | readonly [item: string, index: string];
482
+ /** The joins of `fix`. The join `or` or `max` moves a row up, and `and` or `min` moves a row down (FIX.JOIN). */
483
+ export type FixJoin = "or" | "and" | "max" | "min";
245
484
  /** The largest number of steps of `iterate` (ITERATE.LIMIT). */
246
485
  export declare const MAX_ITERATIONS = 1e5;
486
+ /**
487
+ * The limit of `iterate` from the size of the data (ITERATE.LIMIT.DATA): the number of targets of an axis. This is the
488
+ * number of steps that a `fold` over the axis makes. The axis `list` gives the count of a list. This limit needs step B.
489
+ */
490
+ export interface DataLimit {
491
+ readonly axis: Axis;
492
+ }
247
493
  /** The tag of an expression kind. */
248
494
  export type ExprTag = Expr["tag"];
249
495
  /** An expression of one kind. */
@@ -281,7 +527,23 @@ export declare function fold(axis: Axis, init: Names, step: Names, result: Expr,
281
527
  * This function makes an iteration: up to `limit` steps. `init` gives the names and their first values, and `step`
282
528
  * gives the next values. A true `until` stops it, and `result` gives the value (ITERATE.LIMIT, ITERATE.UNTIL).
283
529
  */
284
- export declare function iterate(limit: number, init: Names, step: Names, result: Expr, until?: Expr): ExprOf<"iterate">;
530
+ export declare function iterate(limit: number | DataLimit, init: Names, step: Names, result: Expr, until?: Expr): ExprOf<"iterate">;
531
+ /**
532
+ * This function makes a fixed-point column (FIX.ROUNDS). `init` gives the first value of each row. `step` gives the next
533
+ * value of each row, and it reads the last round with `last`. `join` joins each next value to the old value of its row.
534
+ */
535
+ export declare function fix(name: string, join: FixJoin, init: Expr, step: Expr): ExprOf<"fix">;
536
+ /** This function makes a read of the value of the focus in the last round of the `fix` with the name `name` (FIX.LAST). */
537
+ export declare function last(name: string): ExprOf<"last">;
538
+ /** This function makes the limit of `iterate` from the size of the data: the number of targets of an axis (ITERATE.LIMIT.DATA). */
539
+ export declare const dataLimit: (axis: Axis) => DataLimit;
540
+ /** This function gives the axis of the data limit of an iteration, or `undefined` for a limit that is a number. */
541
+ export declare const limitAxis: (e: ExprOf<"iterate">) => Axis | undefined;
542
+ /**
543
+ * This function gives the parts of an iteration with a data limit, for a walk that tells the axes apart. The parts are
544
+ * an `each` over the axis, and the iteration without its axis. An iteration with a number has `undefined`.
545
+ */
546
+ export declare function splitLimit(e: ExprOf<"iterate">): readonly [ExprOf<"each">, ExprOf<"iterate">] | undefined;
285
547
  /**
286
548
  * This function makes a function (FN.BIND): the names of its parameters and its body. A function is only the value of
287
549
  * a binding of `let`. The body sees the names of the place of that `let`, so a function cannot call itself.
@@ -457,111 +719,92 @@ export declare function resolveAddr(s: Space, at: Position, addr: readonly Fixed
457
719
  export declare function axisTargets(s: Space, at: Position, a: Exclude<Axis, {
458
720
  readonly t: "where";
459
721
  }>): Result<readonly string[]>;
460
- /**
461
- * Domains. A domain tells which values belong to it and which ops it has. The domain object owns this data.
462
- * Vex does not write to the prototypes of domain classes, and an import has no side effects.
463
- */
464
- /** An algebraic law that an op claims. `@mark1russell7/vex-testkit` checks each claim with property tests. */
465
- export type Law = "commutative" | "associative" | "idempotent";
466
- /** The kind of a parameter. The interpreter checks the arguments of an op that declares its parameters. */
467
- export type ParamKind = "domain" | "number" | "boolean" | "string" | "any";
468
- /** The kind of the result of an op: a kind of a parameter, or `domain:Name` for a value of the domain `Name`. */
469
- export type ReturnKind = ParamKind | `domain:${string}`;
470
- /** The description of one op of a domain. */
471
- export interface OpSpec<D = never> {
472
- /**
473
- * The implementation, for an op that is not a method of the value (static-land style). The first argument
474
- * is the receiver. Without `fn`, the interpreter calls the method of the receiver with the same name.
475
- */
476
- readonly fn?: (self: D, ...args: never[]) => unknown;
477
- /** The laws that the op claims. */
478
- readonly laws?: readonly Law[];
479
- /** The identity element of the op, for reductions over an empty list. */
480
- readonly identity?: () => D;
481
- /** Scalar lifting: `true` lifts each number argument with `fromScalar`. An array sets it for each argument. */
482
- readonly liftScalar?: boolean | readonly boolean[];
483
- /** The kinds of the parameters after the receiver. When set, the interpreter checks the arguments. */
484
- readonly params?: readonly ParamKind[];
485
- /**
486
- * The kind of the result: `domain` for a value of this domain, and `domain:Name` for a value of the domain `Name`. A
487
- * compiler reads it to know the kinds of the values of a program (KIND.RETURNS). The interpreter does not check it,
488
- * and the law checker of the test kit does.
489
- */
490
- readonly returns?: ReturnKind;
722
+ /** The part of an error that does not depend on the position of its node: the kind, the sentence and the op name. */
723
+ export interface ErrorText {
724
+ readonly kind: ErrorKind;
725
+ readonly message: string;
726
+ readonly op?: string;
491
727
  }
492
- /** A JavaScript type of primitive values that a domain can accept. */
493
- export type PrimitiveKind = "number" | "string" | "boolean";
494
- /** The type of an op that lifts number arguments. Use it to type the ops of a domain under `isolatedDeclarations`. */
495
- export type LiftedOp<D> = OpSpec<D> & {
496
- readonly liftScalar: true;
497
- };
498
- /** The type of an op with an implementation function `F`. */
499
- export type FnOp<D, F extends (self: D, ...args: never[]) => unknown> = OpSpec<D> & {
500
- readonly fn: F;
728
+ /** This function gives a short name for the type of a value, for error messages. */
729
+ export declare function describeType(u: unknown): string;
730
+ /** The texts of the errors. Each function takes the facts of the error that do not come from the position of its node. */
731
+ export declare const errorText: {
732
+ /** A name without a binding (`var`). */
733
+ readonly unbound: (name: string) => ErrorText;
734
+ /** A read of a function as a value (FN.VALUE). */
735
+ readonly functionValue: (name: string) => ErrorText;
736
+ /** A call of a name without a binding (FN.CALL). */
737
+ readonly noFunction: (name: string) => ErrorText;
738
+ /** A call of a name that holds a value (FN.CALL). */
739
+ readonly notFunction: (name: string) => ErrorText;
740
+ /** A call with the wrong number of arguments (FN.CALL). */
741
+ readonly arity: (name: string, params: number, args: number) => ErrorText;
742
+ /** An extension kind without a handler. */
743
+ readonly noHandler: (kind: string) => ErrorText;
744
+ /** An exception of an op, of an extension or of `fromScalar`. */
745
+ readonly threw: (op: string) => ErrorText;
746
+ /** A reference that reads no value. `where` is the part of the path that failed. */
747
+ readonly missing: (key: string, where: string) => ErrorText;
748
+ /** A reference whose getter threw. */
749
+ readonly readThrew: (key: string, where: string) => ErrorText;
750
+ /** Two or more arguments or fields that failed (CALL.ARGS, REC.FIELDS). */
751
+ readonly args: (count: number, what: string) => ErrorText;
752
+ /** The axis table of an evaluation without that table. */
753
+ readonly noTable: (name: string) => ErrorText;
754
+ /** The test `until` of `iterate`, with a value that is not a boolean. */
755
+ readonly untilKind: (value: unknown) => ErrorText;
756
+ /** The limit of `iterate` with a test that is not true. */
757
+ readonly limit: (limit: number) => ErrorText;
758
+ /** A value of a row of `fix` of the wrong kind for its join. */
759
+ readonly fixKind: (name: string, join: string, kind: string, value: unknown) => ErrorText;
760
+ /** A value of a row of `fix` that is not a finite number. */
761
+ readonly fixNumber: (name: string, value: unknown) => ErrorText;
762
+ /** The limit of the rounds of `fix`. */
763
+ readonly fixLimit: (name: string, rounds: number) => ErrorText;
764
+ /** A read of `last` at a key that is not a row. */
765
+ readonly lastKey: (name: string, key: string) => ErrorText;
766
+ /** The test of `where`, with a value that is not a boolean. */
767
+ readonly whereKind: (value: unknown) => ErrorText;
768
+ /** A domain that accepts the receiver of an op and has no such op. */
769
+ readonly domainNoOp: (domain: string, op: string) => ErrorText;
770
+ /** An op without arguments and without a free function. */
771
+ readonly noOp: (op: string) => ErrorText;
772
+ /** An op whose receiver no domain accepts. */
773
+ readonly noDomain: (op: string, self: unknown) => ErrorText;
774
+ /** A special form without the argument at the index `i`. */
775
+ readonly needsArgument: (op: string, i: number) => ErrorText;
776
+ /** `and` or `or` without arguments. */
777
+ readonly needsArguments: (op: string) => ErrorText;
778
+ /** An argument of a special form that is not a boolean. */
779
+ readonly notBoolean: (op: string, i: number, value: unknown) => ErrorText;
780
+ /** An argument of an op that does not have the kind of its parameter. */
781
+ readonly badParam: (op: string, i: number, value: unknown, kind: ParamKind, domain: string) => ErrorText;
782
+ /** An op that gave `undefined` or `null`. */
783
+ readonly noValue: (op: string) => ErrorText;
784
+ /** An op that gave a number that is not finite. */
785
+ readonly notFinite: (op: string, value: number) => ErrorText;
786
+ /** An op that gave a value that its domain does not accept as valid. */
787
+ readonly invalid: (op: string, domain: string) => ErrorText;
788
+ /** A check `valid` of a domain that threw. */
789
+ readonly validThrew: (op: string, domain: string) => ErrorText;
790
+ /** A list op whose items must have one kind, with an item of another kind. */
791
+ /** The axis `list` over a value that is not a list (AXIS.LIST). */
792
+ readonly axisList: (value: unknown) => ErrorText;
793
+ readonly needsItems: (op: string, what: "numbers" | "booleans", item: unknown) => ErrorText;
794
+ /** A list op that has no items to work with. */
795
+ readonly empty: (op: string) => ErrorText;
796
+ /** `reduce` with an op name that is not a text. */
797
+ readonly reduceName: (name: unknown) => ErrorText;
798
+ /** A step of `reduce` or of `sortBy` that no domain gives. */
799
+ readonly noStep: (op: string, value: unknown) => ErrorText;
501
800
  };
502
- /**
503
- * The type of an op table: each name in `Names` is an op, and each name in `Lifted` lifts number arguments.
504
- * Use it to type the ops of a domain under `isolatedDeclarations`.
505
- */
506
- export type OpTable<D, Names extends string, Lifted extends string = never> = { readonly [N in Names]: N extends Lifted ? LiftedOp<D> : OpSpec<D>; };
507
- /** The description of a domain, as a caller gives it to `defineDomain`. */
508
- export interface DomainSpec<Name extends string, D, Ops extends Readonly<Record<string, OpSpec<D>>>> {
509
- /** The name of the domain. */
510
- readonly name: Name;
511
- /** The runtime test for the values of the domain. It must not give false positives. */
512
- readonly is: (u: unknown) => u is D;
513
- /**
514
- * The JavaScript type of the values of the domain, if `is` accepts each value of that type and no other value
515
- * (KIND.PRIMITIVE). A compiler then finds the op of such a value before a run.
516
- */
517
- readonly primitive?: PrimitiveKind;
518
- /** The ops of the domain, with their metadata. */
519
- readonly ops: Ops;
520
- /** With `"all"`, each method of a value is an op, also without an entry in `ops`. The default is `"declared"`. */
521
- readonly methods?: "declared" | "all";
522
- /** The scalar lift: it makes a domain value from a number. */
523
- readonly fromScalar?: (n: number) => D;
524
- /** A check of the values that ops give. A value that fails the check gives the error `#NUM!`. */
525
- readonly valid?: (d: D) => boolean;
526
- /** A short text for a value, for traces and the site. */
527
- readonly show?: (d: D) => string;
528
- /** The JSON form of a value, for literals in serialized programs. */
529
- readonly encode?: (d: D) => unknown;
530
- /** The value of a JSON form that `encode` made. */
531
- readonly decode?: (json: unknown) => D;
532
- /**
533
- * Some values of the domain. A compiler gives them to an op and to its copy in a module: the two must give the same
534
- * results (KIND.DOMAIN).
535
- */
536
- readonly samples?: () => readonly D[];
537
- }
538
- /** A domain. Make one with `defineDomain`. */
539
- export interface Domain<Name extends string = string, D = unknown, Ops extends Readonly<Record<string, OpSpec<D>>> = Readonly<Record<string, OpSpec<D>>>> extends DomainSpec<Name, D, Ops> {
540
- readonly kind: "vex.domain";
541
- }
542
- /** A domain with any value type. The interpreter uses this type. */
543
- export type AnyDomain = Domain<string, any, Readonly<Record<string, OpSpec<any>>>>;
544
- /** This function makes a domain. The result is frozen. */
545
- export declare function defineDomain<const Name extends string, D, const Ops extends Readonly<Record<string, OpSpec<D>>>>(spec: DomainSpec<Name, D, Ops>): Domain<Name, D, Ops>;
546
- /** This function tells if a name can be an op name. */
547
- export declare const isOpName: (name: string) => boolean;
548
- /**
549
- * This function finds a method on a value: an own function property, or a function on the prototype chain.
550
- * It stops at `Object.prototype` and `Function.prototype`, so inherited members (for example `toString`) are not ops.
551
- */
552
- export declare function findMethod(self: unknown, name: string): ((...args: unknown[]) => unknown) | undefined;
553
- /** An op that the interpreter found for a receiver. */
554
- export interface ResolvedOp {
555
- readonly domain: AnyDomain;
556
- readonly spec: OpSpec<unknown>;
557
- readonly call: (args: readonly unknown[]) => unknown;
801
+ /** The details of an error that come from its evaluation, and not from its text. */
802
+ export interface ErrorExtra {
803
+ readonly causes?: readonly VexError[];
804
+ readonly thrown?: unknown;
558
805
  }
559
- /** This function finds the op `name` for `self` in one domain. It gives `undefined` if the domain does not have it. */
560
- export declare function resolveOp(domain: AnyDomain, self: unknown, name: string): ResolvedOp | undefined;
561
- /** This function gives the domain of a value: the first domain whose `is` accepts it. */
562
- export declare function domainOf(domains: readonly AnyDomain[], value: unknown): AnyDomain | undefined;
563
- /** This function tells if the `liftScalar` setting lifts the argument at `index`. */
564
- export declare const liftsAt: (lift: OpSpec<unknown>["liftScalar"], index: number) => boolean;
806
+ /** This function makes the error of a text at a node: the path of the node, with its origin and its focus. */
807
+ export declare function errorAt(t: ErrorText, pos: Position, path: readonly number[], extra?: ErrorExtra): VexError;
565
808
  /** One item of a list: the key of the target and the result of the body there. */
566
809
  export interface ListItem<T = unknown> {
567
810
  readonly key: string;
@@ -584,13 +827,19 @@ export declare const isVexList: (u: unknown) => u is VexList;
584
827
  * The name of a core list op. `sortBy`, `take`, `drop`, `append`, `flat` and `without` give a list (LIST.BUILD), and
585
828
  * the other ops give a value. `get` gives the value at a key (LIST.GET), and `indexOf` gives the position of a value
586
829
  * (LIST.INDEXOF). `distinct` and `group` give a list, and `join` gives a text (LIST.DISTINCT, LIST.GROUP, LIST.JOIN).
830
+ * `setNth` gives a list with a new value at one position (LIST.SETNTH).
587
831
  */
588
- export type ListOp = "count" | "sum" | "min" | "max" | "mean" | "any" | "all" | "none" | "values" | "keys" | "reduce" | "first" | "errors" | "sortBy" | "take" | "nth" | "drop" | "append" | "flat" | "without" | "get" | "indexOf" | "distinct" | "group" | "join";
832
+ export type ListOp = "count" | "sum" | "min" | "max" | "mean" | "any" | "all" | "none" | "values" | "keys" | "reduce" | "first" | "errors" | "sortBy" | "take" | "nth" | "setNth" | "drop" | "append" | "flat" | "without" | "get" | "indexOf" | "distinct" | "group" | "join";
589
833
  /**
590
834
  * The names of the core list ops. They apply when the first argument is a list. They apply to an array too, when no
591
835
  * domain and no function of the host has the op for it (LIST.ARRAY).
592
836
  */
593
837
  export declare const LIST_OPS: ReadonlySet<string>;
838
+ /**
839
+ * The size rules of the core list ops and of `fill` (LOOP.SIZE.OPS). Each op that gives a list has a rule here. An
840
+ * error item has no size, so `errors` has no bound: the messages of the errors can hold texts.
841
+ */
842
+ export declare const LIST_SIZES: Readonly<Record<ListOp | "fill", SizeRule>>;
594
843
  /** This function tells if a name is the name of a core list op. */
595
844
  export declare const isListOp: (op: string) => op is ListOp;
596
845
  /** The options of a list op. */
@@ -598,6 +847,8 @@ export interface ListOptions {
598
847
  /** With `true`, any error item makes the result that error. The default skips error items. */
599
848
  readonly strict?: boolean;
600
849
  }
850
+ /** This function gives a list, the list of an array, or `undefined` for another value (LIST.ARRAY). */
851
+ export declare const asList: (u: unknown, missing: (message: string) => VexError) => VexList | undefined;
601
852
  /** One field read of a reference: the key and the path that it read, and if the read found a value. */
602
853
  export interface Read {
603
854
  readonly key: string;
@@ -617,6 +868,11 @@ export interface TraceEvent {
617
868
  readonly focus: string;
618
869
  /** The field reads of a reference node. */
619
870
  readonly reads?: readonly Read[];
871
+ /** The round of a `fix`: its count from 0, and the keys of the rows that it changed (FIX.TRACE). The result is the column. */
872
+ readonly round?: {
873
+ readonly index: number;
874
+ readonly changed: readonly string[];
875
+ };
620
876
  /** The result of the node. */
621
877
  readonly result: Result<unknown>;
622
878
  }
@@ -646,8 +902,54 @@ export declare function toDocument(e: Expr, domains?: readonly AnyDomain[]): Res
646
902
  * deeper than the kernel takes gives `#DEPTH!` (DOC.ERROR). The expression of a valid document is valid (EVAL.SHAPE).
647
903
  */
648
904
  export declare function fromDocument(doc: unknown, domains?: readonly AnyDomain[]): Result<Expr>;
649
- /** A free function op. The interpreter gives it the values of all arguments. */
650
- export type FreeFn = (...args: readonly unknown[]) => unknown;
905
+ /** A step of Vex. Step A has loops with a fixed count. Step B adds limits from the data and fixed points. Step C adds functions that call themselves, with a budget. */
906
+ type VexStep = "A" | "B" | "C";
907
+ /** The construct of an `iterate` with a limit from the data. */
908
+ declare const ITERATE_SIZE = "iterate.size";
909
+ /** The step that each construct of Vex needs. The name of a construct is the tag of its node, or `ITERATE_SIZE`. */
910
+ export declare const CONSTRUCT_STEPS: Readonly<Record<ExprTag | typeof ITERATE_SIZE, VexStep>>;
911
+ /** The steps of Vex, from the lowest to the highest. */
912
+ export declare const VEX_STEP_NAMES: readonly VexStep[];
913
+ /** The ladder of the steps of Vex: the steps and the step of each construct. */
914
+ export declare const VEX_STEPS: StepLadder<VexStep>;
915
+ /** The highest step that a host accepts without the option `maxStep`. */
916
+ export declare const DEFAULT_MAX_STEP: VexStep;
917
+ /** The options of the check of steps: the highest step that the host accepts. */
918
+ export interface StepOptions {
919
+ /** The highest step that the host accepts. The default is `DEFAULT_MAX_STEP`, step B. */
920
+ readonly maxStep?: VexStep;
921
+ }
922
+ /** The step of a program, with the reason as text, and the construct and the path of the node that needs the step. */
923
+ export interface ProgramStep {
924
+ readonly step: VexStep;
925
+ /** The reason as text. */
926
+ readonly reason: string;
927
+ /** The construct that needs the step. A program of step A has none. */
928
+ readonly construct?: string;
929
+ /** The path of the node of the construct, as child indexes (EVAL.LOCATION). A program of step A has none. */
930
+ readonly path?: readonly number[];
931
+ }
932
+ /**
933
+ * This function gives the lowest step that a program needs, with the reason (STEP.LOWEST). The reason names the first
934
+ * node in the order of `children` whose construct needs that step. The program must have a valid shape (EVAL.SHAPE).
935
+ */
936
+ export declare function programStep(e: Expr): ProgramStep;
937
+ /**
938
+ * This function gives the reason that a host refuses a program for its step, or `undefined` (STEP.MAX). A program of a
939
+ * step above the option `maxStep` is not valid, and the reason names the step that it needs. A value of `maxStep` that
940
+ * is not a step of Vex is not valid too. The program must have a valid shape (EVAL.SHAPE).
941
+ */
942
+ export declare function stepError(e: Expr, opts?: StepOptions): string | undefined;
943
+ /**
944
+ * A free function op. The interpreter gives it the values of all arguments. The property `size` is its size rule
945
+ * (LOOP.SIZE.OPS). Without it, a step of a loop cannot use its result in the size of a list name. The property
946
+ * `returns` is the kind of its result, as in `OpSpec`. The interpreter does not examine it.
947
+ */
948
+ export type FreeFn = ((...args: readonly unknown[]) => unknown) & {
949
+ readonly size?: SizeRule;
950
+ readonly returns?: ReturnKind;
951
+ readonly monotone?: readonly Monotone[];
952
+ };
651
953
  /** The context of an extension handler. */
652
954
  export interface ExtContext {
653
955
  readonly space: Space;
@@ -674,13 +976,18 @@ export interface EvalOptions {
674
976
  readonly tables?: Readonly<Record<string, Space>>;
675
977
  /** A receiver of trace events. */
676
978
  readonly trace?: TraceSink;
979
+ /**
980
+ * The highest step of the language that the host accepts (STEP.MAX). The default is B. A program that needs a higher
981
+ * step gives `#VALUE!` before the evaluation, and the reason names its step.
982
+ */
983
+ readonly maxStep?: VexStep;
677
984
  }
678
985
  /** The name of a special form. */
679
986
  export type SpecialForm = "if" | "and" | "or" | "ifError";
680
987
  /** The names of the special forms. Their arguments are not evaluated before the call. */
681
988
  export declare const SPECIAL_FORMS: ReadonlySet<string>;
682
989
  /** The options that a compiled program keeps: the domains, the free functions and the extension handlers. */
683
- export type CompileOptions = Pick<EvalOptions, "domains" | "fns" | "extensions">;
990
+ export type CompileOptions = Pick<EvalOptions, "domains" | "fns" | "extensions" | "maxStep">;
684
991
  /** The options of one run of a compiled program. */
685
992
  export type RunOptions = Pick<EvalOptions, "space" | "origin" | "vars" | "trace" | "tables">;
686
993
  /**
@@ -698,14 +1005,32 @@ export interface Program {
698
1005
  /** This method evaluates the program at an origin, with a trace of each node. */
699
1006
  explain(opts: Omit<RunOptions, "trace">): Trace;
700
1007
  }
1008
+ /** This function gives the error of an origin that is not a key of the space (EVAL.ORIGIN). */
1009
+ export declare const noKeyError: (origin: string) => VexError;
701
1010
  /** The deepest nesting of an expression that `compile` accepts (EVAL.NESTING). */
702
1011
  export declare const MAX_NESTING = 500;
703
1012
  /** This function gives the number of nodes on the longest path from the root of `e`. It uses a stack, not recursion. */
704
1013
  export declare function nestingOf(e: Expr): number;
1014
+ /** This function gives the reason of the refusal of an expression that is nested too deep (EVAL.NESTING), or undefined. */
1015
+ export declare function nestingError(e: Expr): string | undefined;
705
1016
  /**
706
1017
  * This function compiles an expression or a document (DOC.ENTRY). The result gives the same results and the same traces
707
1018
  * as `evaluate`, because `evaluate` uses it too.
708
1019
  */
1020
+ /**
1021
+ * The list ops of `compile` for the values of a host (LIST.OPS). A result has the rules of the interpreter. An error of
1022
+ * the op has the position and the path of the call, and an error of an item keeps its own.
1023
+ */
1024
+ export interface ListOps {
1025
+ /** This function gives the result of a list op on a list. The list is the receiver, and `rest` has the other arguments. */
1026
+ readonly list: (op: ListOp, list: VexList, rest: readonly unknown[], position: Position, path: readonly number[]) => Result<unknown>;
1027
+ /** This function gives the result of a list op on an array (LIST.ARRAY). A missing item is an error item with the position and the path. */
1028
+ readonly array: (op: ListOp, array: readonly unknown[], rest: readonly unknown[], position: Position, path: readonly number[]) => Result<unknown>;
1029
+ /** This function gives the result of `fill` (LIST.FILL). */
1030
+ readonly fill: (values: readonly unknown[], position: Position, path: readonly number[]) => Result<VexList>;
1031
+ }
1032
+ /** This function gives the list ops of `compile` for the options. It keeps the index of each list that `get` read. */
1033
+ export declare function listOps(opts?: CompileOptions): ListOps;
709
1034
  export declare function compile(source: Expr | Envelope, opts?: CompileOptions): Program;
710
1035
  /** This function evaluates an expression or a document at the origin of a space. It does not throw. */
711
1036
  export declare function evaluate(expr: Expr | Envelope, opts: EvalOptions): Result<unknown>;
@@ -721,8 +1046,6 @@ export declare const isFieldName: (seg: string) => boolean;
721
1046
  export declare function safeIs(d: AnyDomain, value: unknown): boolean;
722
1047
  /** This function tells if an argument has the kind of a parameter of an op of the domain `domain`. */
723
1048
  export declare function matchesKind(kind: ParamKind, value: unknown, domain: AnyDomain): boolean;
724
- /** This function gives a short name for the type of a value, for error messages. */
725
- export declare function describeType(u: unknown): string;
726
1049
  /** This function gives the label of a node, for traces. */
727
1050
  export declare function labelOf(e: Expr): string;
728
1051
  /** This function gives a short text for a value. */
@@ -889,14 +1212,20 @@ export declare function traversal<K extends string, T>(items: readonly Traversal
889
1212
  export declare const CELL_KIND = "vex.cell";
890
1213
  /**
891
1214
  * The data of a cell reference: the column, and the address from the focus. The data of an extension is not an
892
- * expression, so the address has only fixed moves.
1215
+ * expression, so the address has only fixed moves. `cell` takes computed moves in another form.
893
1216
  */
894
1217
  export interface CellRef {
895
1218
  readonly column: string;
896
1219
  readonly at: readonly FixedMove[];
897
1220
  }
898
- /** This function makes a cell reference: the column `column` at the address `at` from the focus. */
899
- export declare const cell: (column: string, at?: readonly FixedMove[]) => Expr;
1221
+ /**
1222
+ * This function makes a read of the column `column` at the address `at` from the focus. An address of fixed moves gives
1223
+ * a cell reference. A computed move is an expression, not data (SHEET.CELL.COMPUTED). Thus it goes in the address of the
1224
+ * axis `window(0, 0)`, and the read is the one item of that axis. Each tier and the JSON form have this form.
1225
+ */
1226
+ export declare const cell: (column: string, at?: Addr) => Expr;
1227
+ /** This function tells if the data of an extension is a cell reference: a column, and an address of fixed moves. */
1228
+ export declare const isCellRef: (u: unknown) => u is CellRef;
900
1229
  /** The formulas of single cells: for each column, the formula of each key that has its own formula. */
901
1230
  export type CellFormulas = ReadonlyMap<string, ReadonlyMap<string, Expr>>;
902
1231
  /** A table of a run: its space, the formulas of its columns, and the formulas of its cells. */
@@ -922,6 +1251,22 @@ export type SheetOptions = Omit<EvalOptions, "origin" | "trace" | "tables"> & {
922
1251
  };
923
1252
  /** A compiler of the formulas of the columns of a run. */
924
1253
  export type CompileFn = (expr: Expr, options: CompileOptions) => Program;
1254
+ /** A direction of the reads of a column from itself: to an earlier key, to a later key, or down a tree to the children. */
1255
+ export type Direction = "before" | "after" | "down";
1256
+ /**
1257
+ * This function gives the columns that the formulas of the column `self` read with a cell reference: its formula and
1258
+ * the formulas of its cells. It also gives the directions of their reads of the column itself. A read in the body or
1259
+ * in a test of an axis also has the direction of that axis. It walks each expression with a stack, not with recursion.
1260
+ */
1261
+ export declare function readsOf(columns: ReadonlyMap<string, Expr>, cells: CellFormulas, self: string): {
1262
+ readonly columns: ReadonlySet<string>;
1263
+ readonly directions: ReadonlySet<Direction>;
1264
+ };
1265
+ /**
1266
+ * This function gives the columns of a sheet in an order where each column comes after the columns that it reads.
1267
+ * The columns of a cycle keep their order. The columns with formulas of cells only come last.
1268
+ */
1269
+ export declare function columnOrder(columns: ReadonlyMap<string, Expr>, cells: CellFormulas): readonly string[];
925
1270
  /**
926
1271
  * One run of a sheet. It keeps the result of each cell that it evaluated. The space does not change, so a cell has
927
1272
  * one result in a run.
@@ -975,6 +1320,11 @@ export interface Arg<T> {
975
1320
  /** This phantom member carries the type. It is not present at run time. */
976
1321
  readonly [ARG_TYPE]?: T;
977
1322
  }
1323
+ /**
1324
+ * The value of a column with the join `J`: a boolean for `or` and `and`, and a number for `max` and `min` (FIX.KIND). A
1325
+ * union of joins has no one kind, so it gives `never`.
1326
+ */
1327
+ export type FixValue<J extends FixJoin> = [J] extends ["or" | "and"] ? boolean : [J] extends ["max" | "min"] ? number : never;
978
1328
  /** The keys of any member of a union of record types. */
979
1329
  type AllKeys<O> = O extends unknown ? keyof O : never;
980
1330
  /** The type of field `P` in the members of `O` that have it. */
@@ -1098,16 +1448,23 @@ export interface ChainBase<Ctx extends ChainContext, T> {
1098
1448
  /** This method evaluates each branch with the current value, and gives a record of the results. */
1099
1449
  fork<const B extends Readonly<Record<string, (c: ChainOf<Ctx, T>) => ChainBase<Ctx, unknown>>>>(branches: B): ChainOf<Ctx, { readonly [N in keyof B]: ValueOf<ReturnType<B[N]>>; }>;
1100
1450
  /**
1101
- * This method makes up to `limit` steps (ITERATE.LIMIT). `init` gives the names and their first values, and `step`
1102
- * gives the next values. A true `until` stops the steps (ITERATE.UNTIL). `result` gives the value of the chain. A
1103
- * name with a list chain as its first value is a list chain (BUILD.LIST.LOOP), and a list result gives a list chain.
1451
+ * This method makes up to `limit` steps (ITERATE.LIMIT). A list chain or a `DataLimit` gives a limit from the data
1452
+ * (ITERATE.LIMIT.DATA). `init` gives the names and their first values, and `step` gives the next values. A true
1453
+ * `until` stops the steps (ITERATE.UNTIL). `result` gives the value of the chain. A name with a list chain as its
1454
+ * first value is a list chain (BUILD.LIST.LOOP), and a list result gives a list chain.
1104
1455
  */
1105
- iterate<const I extends Readonly<Record<string, unknown>>, U>(limit: number, init: I, step: (vars: LoopVars<Ctx, I>) => NoInfer<LoopStep<Ctx, I>>, result: (vars: LoopVars<Ctx, I>) => ListChain<Ctx, U>, opts?: {
1456
+ iterate<const I extends Readonly<Record<string, unknown>>, U>(limit: number | DataLimit | ListChain<Ctx, unknown>, init: I, step: (vars: LoopVars<Ctx, I>) => NoInfer<LoopStep<Ctx, I>>, result: (vars: LoopVars<Ctx, I>) => ListChain<Ctx, U>, opts?: {
1106
1457
  readonly until?: (vars: LoopVars<Ctx, I>) => ArgInput<boolean, Ctx, false>;
1107
1458
  }): ListChain<Ctx, U>;
1108
- iterate<const I extends Readonly<Record<string, unknown>>, R>(limit: number, init: I, step: (vars: LoopVars<Ctx, I>) => NoInfer<LoopStep<Ctx, I>>, result: (vars: LoopVars<Ctx, I>) => ArgInput<R, Ctx, false>, opts?: {
1459
+ iterate<const I extends Readonly<Record<string, unknown>>, R>(limit: number | DataLimit | ListChain<Ctx, unknown>, init: I, step: (vars: LoopVars<Ctx, I>) => NoInfer<LoopStep<Ctx, I>>, result: (vars: LoopVars<Ctx, I>) => ArgInput<R, Ctx, false>, opts?: {
1109
1460
  readonly until?: (vars: LoopVars<Ctx, I>) => ArgInput<boolean, Ctx, false>;
1110
1461
  }): ChainOf<Ctx, R>;
1462
+ /**
1463
+ * This method makes a fixed-point column (BUILD.FIX). `init` gives each row its value of round 0. `step` gets a chain
1464
+ * of the last round at the focus, and it gives the next value of the row. `join` keeps each row on one way (FIX.JOIN).
1465
+ * The value of the chain is the row of the focus, and the rounds end when no row changes (FIX.ROUNDS).
1466
+ */
1467
+ fix<J extends FixJoin>(name: string, join: J, init: ArgInput<FixValue<J>, Ctx, false>, step: (last: ChainOf<Ctx, FixValue<J>>) => NoInfer<ArgInput<FixValue<J>, Ctx, false>>): ChainOf<Ctx, FixValue<J>>;
1111
1468
  /** This method binds names for the body. The body gets a variable token for each name. */
1112
1469
  with<const B extends Readonly<Record<string, unknown>>, U>(binds: B, body: (c: ChainOf<Ctx, T>, vars: { readonly [N in keyof B]: Arg<ArgValue<Ctx, B[N]>>; }) => ChainBase<Ctx, U>): ChainOf<Ctx, U>;
1113
1470
  /**
@@ -1256,6 +1613,11 @@ export interface ListChain<Ctx extends ChainContext, U> {
1256
1613
  take(n: number, opts?: ListOpts): ListChain<Ctx, U>;
1257
1614
  /** The value of the item at the position `i`, from 0 (LIST.NTH). */
1258
1615
  nth(i: number, opts?: ListOpts): ChainOf<Ctx, U>;
1616
+ /**
1617
+ * This list with `value` as the value of the item at the position `i`, from 0 (LIST.SETNTH). The item keeps its key.
1618
+ * A chain or `lit` gives the value, and a chain can give the position. Both evaluate at the focus.
1619
+ */
1620
+ setNth<V>(i: number | ChainBase<Ctx, number>, value: ChainBase<Ctx, V> | Arg<V>, opts?: ListOpts): ListChain<Ctx, U | V>;
1259
1621
  /**
1260
1622
  * The value of the first item with the key `k` (LIST.GET). A chain of a text gives the key, and it evaluates at the
1261
1623
  * focus. A key that no item has gives `#N/A`. Thus a step reads the old value of each key.
@@ -1339,13 +1701,13 @@ export interface Root<Ctx extends ChainContext> {
1339
1701
  /** The root of a column formula: the root of the builder, and references to the cells of the sheet. */
1340
1702
  export interface SheetRoot<Ctx extends ChainContext, Cols> extends Root<Ctx> {
1341
1703
  /**
1342
- * This method makes a cell reference: the column `column` at the key `at`, or at the address `at` from the focus.
1343
- * The address has only fixed moves. Without `at`, it reads at the focus. The type is the type of a column before
1344
- * this one.
1704
+ * This method reads a cell: the column `column` at the key `at`, or at the address `at` from the focus. The address
1705
+ * can have computed moves (SHEET.CELL.COMPUTED). Without `at`, it reads at the focus. The type is the type of a column
1706
+ * before this one.
1345
1707
  */
1346
- cell<N extends keyof Cols & string>(column: N, at?: Ctx["keys"] | readonly FixedMove[]): Arg<Cols[N]>;
1708
+ cell<N extends keyof Cols & string>(column: N, at?: Ctx["keys"] | Addr): Arg<Cols[N]>;
1347
1709
  /** This method makes a cell reference to any column, also this column or a later one. The caller gives the type. */
1348
- cell<T>(column: string, at?: Ctx["keys"] | readonly FixedMove[]): Arg<T>;
1710
+ cell<T>(column: string, at?: Ctx["keys"] | Addr): Arg<T>;
1349
1711
  }
1350
1712
  /** One row of a sheet: the key and the result of each column. */
1351
1713
  export interface SheetRow<K extends string, Cols> {
@@ -1416,5 +1778,47 @@ export declare function vex<const Dms extends readonly AnyDomain[]>(...domains:
1416
1778
  };
1417
1779
  /** The type of a domain value, from the domain object. */
1418
1780
  export type ValueOfDomain<Dm> = DomainValue<Dm>;
1419
- export type { Envelope, Json };
1781
+ /** The options of the check: the domains and the functions of the host, as the options of a compilation give them. */
1782
+ interface MonotoneOptions {
1783
+ readonly domains?: readonly AnyDomain[];
1784
+ readonly fns?: Readonly<Record<string, unknown>>;
1785
+ }
1786
+ /** This function gives the reason that a program breaks a rule of `fix`, or `undefined` for a program that keeps them (FIX.LAST, FIX.MONOTONE). */
1787
+ export declare function monotoneError(e: Expr, opts: MonotoneOptions): string | undefined;
1788
+ /**
1789
+ * This function gives the largest number of rounds of a column of `rows` rows. A boolean column changes at least one row
1790
+ * in each round before the last, and a row changes one time. A path has fewer rows than the column, so a number
1791
+ * column stops in this bound when its steps follow paths (FIX.LIMIT).
1792
+ */
1793
+ export declare const fixRounds: (rows: number) => number;
1794
+ /** This function gives the kind of the values of a join. */
1795
+ export declare const joinKind: (join: FixJoin) => "boolean" | "number";
1796
+ /** This function gives the reason that a value cannot be a value of a row, or `undefined` for a good value (FIX.KIND). */
1797
+ export declare function fixValueError(name: string, join: FixJoin, value: unknown): ErrorText | undefined;
1798
+ /**
1799
+ * This function gives the error that stands for the failed rows of a round, or `undefined` when `#ARGS` must collect them
1800
+ * (FIX.ERROR). `#DEPTH!` wins. `#CYCLE!` comes next, so a cell on a cycle reports the cycle (SHEET.CYCLE).
1801
+ */
1802
+ export declare function worstRow<E extends {
1803
+ readonly code: string;
1804
+ }>(errors: readonly E[]): E | undefined;
1805
+ /** The options of the check of sizes: the domains and the functions of the host, as for `compile`. */
1806
+ export interface SizeOptions {
1807
+ readonly domains?: readonly AnyDomain[];
1808
+ /** The functions of the host. A function with the property `size` has that size rule, and another function has none. */
1809
+ readonly fns?: Readonly<Record<string, unknown>>;
1810
+ }
1811
+ /**
1812
+ * This function gives the size rule of an op of a domain (LOOP.SIZE.OPS). The rule is the rule of the op, or a rule
1813
+ * from its result kind and from the domain. The function gives `undefined` for an op without a rule.
1814
+ */
1815
+ export declare function ruleOf(d: AnyDomain, spec: OpSpec<unknown>, domains: readonly AnyDomain[]): SizeRule | undefined;
1816
+ /**
1817
+ * This function checks the sizes of the loops of an expression (LOOP.SIZE). It gives the reason of a refusal, or
1818
+ * `undefined`. The expression must pass `shapeError` and the limit of the nesting first. Each reading gives a sound
1819
+ * bound, so one reading that accepts the expression makes it valid. A refusal tells the reason of the first reading
1820
+ * (LOOP.SIZE.READINGS).
1821
+ */
1822
+ export declare function sizeError(e: Expr, opts?: SizeOptions): string | undefined;
1823
+ export type { Envelope, Json, MonotoneOptions, VexStep };
1420
1824
  //# sourceMappingURL=index.d.ts.map