@mark1russell7/coeval 0.16.0 → 0.18.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/README.md +9 -4
- package/build/index.d.ts +545 -233
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2619 -383
- package/build/index.js.map +1 -1
- package/package.json +3 -2
- package/src/agree.ts +128 -16
- package/src/conform.ts +75 -5
- package/src/deref.ts +76 -11
- package/src/evaluate.ts +151 -21
- package/src/facts.ts +113 -78
- package/src/formula.ts +67 -11
- package/src/index.ts +23 -1
- package/src/merge.ts +49 -14
- package/src/reference.ts +110 -15
- package/src/replay.ts +1052 -18
- package/src/static.ts +2 -2
- package/src/stdlib.ts +55 -2
- package/src/syntax.ts +357 -52
- package/src/types.ts +520 -17
package/src/static.ts
CHANGED
|
@@ -619,9 +619,9 @@ const FOLD_NAMES: readonly string[] = /* @__PURE__ */ Object.freeze(["acc", "ite
|
|
|
619
619
|
|
|
620
620
|
/**
|
|
621
621
|
* This function gives each equation of the tree contract of a kind, with the names that it sees (D42). An equation of
|
|
622
|
-
* `equations`, a `unit` and a `default` see no names.
|
|
622
|
+
* `equations`, a `unit` and a `default` see no names. `check` and `factsOf` read the equations with this one function.
|
|
623
623
|
*/
|
|
624
|
-
function equationsOf(kind: Kind): readonly { readonly label: string; readonly term: Json; readonly names: readonly string[] }[] {
|
|
624
|
+
export function equationsOf(kind: Kind): readonly { readonly label: string; readonly term: Json; readonly names: readonly string[] }[] {
|
|
625
625
|
const tree = kind.tree;
|
|
626
626
|
if (tree === undefined) return [];
|
|
627
627
|
const out: { readonly label: string; readonly term: Json; readonly names: readonly string[] }[] = [];
|
package/src/stdlib.ts
CHANGED
|
@@ -2,12 +2,15 @@ import { type Json, type Key, field, isRecord } from "./doc.ts";
|
|
|
2
2
|
import {
|
|
3
3
|
type EvalInput,
|
|
4
4
|
type Evaluator,
|
|
5
|
+
type InputWithRuntime,
|
|
5
6
|
type Machine,
|
|
6
7
|
type Plan,
|
|
7
8
|
type Result,
|
|
8
9
|
type RunPart,
|
|
9
10
|
type Runner,
|
|
10
11
|
type Steps,
|
|
12
|
+
RUNTIME,
|
|
13
|
+
evaluateWithin,
|
|
11
14
|
fail,
|
|
12
15
|
ok,
|
|
13
16
|
planner,
|
|
@@ -17,6 +20,7 @@ import { type Cap, type HostThing, type Thing, type Walker, THING, isHostThing,
|
|
|
17
20
|
import type { World } from "./ladder.ts";
|
|
18
21
|
import { type AttributeDeclaration, type TreeContract, equationType, lookupKind } from "./world.ts";
|
|
19
22
|
import { STD_DOMAINS } from "./types.ts";
|
|
23
|
+
import type { SyntaxProfile } from "./syntax.ts";
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
26
|
* The world of the examples: small kinds for numbers, lists, conditions, names, sequences and effects.
|
|
@@ -127,6 +131,52 @@ export const STD_WORLD: World = {
|
|
|
127
131
|
defaults: { view: "view.card" },
|
|
128
132
|
};
|
|
129
133
|
|
|
134
|
+
/**
|
|
135
|
+
* The text syntax of the standard world (K162, D64). The syntax kit (D41) reads it, thus a host of `STD_WORLD` does
|
|
136
|
+
* not write its own profile. The operators `>`, `+` and `*` make `greater`, `add` and `multiply`. A call form makes
|
|
137
|
+
* each other kind, and `ref` uses the reference syntax of the kit.
|
|
138
|
+
*
|
|
139
|
+
* A literal in a place that takes a document gets its data envelope (K159, D65). Such a place is a part of `if`,
|
|
140
|
+
* `list`, `seq` or `pure`, the value of `write`, or the whole text. The document after a header name is such a place
|
|
141
|
+
* too. Thus `list(1, "a")` evaluates to `[1, "a"]`. The forms `add`, `multiply` and `greater` write an operator document that its operator
|
|
142
|
+
* does not write, for example `add(5)` (K163).
|
|
143
|
+
*
|
|
144
|
+
* A host with more kinds spreads this profile and adds its forms to `calls.forms`. `STD_SYNTAX` stays the profile of
|
|
145
|
+
* the formula kit.
|
|
146
|
+
*/
|
|
147
|
+
export const WORLD_SYNTAX: SyntaxProfile = /* @__PURE__ */ Object.freeze({
|
|
148
|
+
operators: [
|
|
149
|
+
{ symbol: ">", fixity: "infix", prec: 4, assoc: "none", kind: "greater" },
|
|
150
|
+
{ symbol: "+", fixity: "infix", prec: 5, assoc: "flat", kind: "add" },
|
|
151
|
+
{ symbol: "*", fixity: "infix", prec: 6, assoc: "flat", kind: "multiply" },
|
|
152
|
+
],
|
|
153
|
+
calls: {
|
|
154
|
+
ops: [],
|
|
155
|
+
forms: [
|
|
156
|
+
{ name: "if", kind: "if", fields: ["test", "then", "else"], min: 2, wrap: true },
|
|
157
|
+
{ name: "list", kind: "list", wrap: true },
|
|
158
|
+
{ name: "seq", kind: "seq", wrap: true },
|
|
159
|
+
{ name: "pure", kind: "pure", min: 1, wrap: true },
|
|
160
|
+
{ name: "log", kind: "log", min: 1 },
|
|
161
|
+
{ name: "write", kind: "write", fields: ["key", "value"], wrap: ["value"] },
|
|
162
|
+
{ name: "math.sum", kind: "math.sum" },
|
|
163
|
+
{ name: "math.product", kind: "math.product" },
|
|
164
|
+
{ name: "number", kind: "number", args: "literal" },
|
|
165
|
+
{ name: "text", kind: "text", args: "literal" },
|
|
166
|
+
{ name: "bool", kind: "bool", args: "literal" },
|
|
167
|
+
{ name: "panel", kind: "panel", args: "named", fields: ["width", "height", "children"] },
|
|
168
|
+
{ name: "box", kind: "box", args: "named", fields: ["width", "height", "children"] },
|
|
169
|
+
{ name: "nearest", kind: "nearest", args: "named", fields: ["type", "follow", "self"] },
|
|
170
|
+
// An operator document with fewer terms than its operator takes, for example add(5) (K163, D65).
|
|
171
|
+
{ name: "add", kind: "add" },
|
|
172
|
+
{ name: "multiply", kind: "multiply" },
|
|
173
|
+
{ name: "greater", kind: "greater" },
|
|
174
|
+
],
|
|
175
|
+
},
|
|
176
|
+
literals: { envelopes: { number: "number", text: "text", bool: "bool" } },
|
|
177
|
+
header: { bind: "=" },
|
|
178
|
+
} satisfies SyntaxProfile);
|
|
179
|
+
|
|
130
180
|
function isNumber(value: unknown): value is number {
|
|
131
181
|
return typeof value === "number" && Number.isFinite(value);
|
|
132
182
|
}
|
|
@@ -234,7 +284,8 @@ interface NodeState {
|
|
|
234
284
|
*/
|
|
235
285
|
read(key: string): Result | undefined;
|
|
236
286
|
/**
|
|
237
|
-
* This function evaluates an equation of the kind of the node, with the node as `self` and no capabilities.
|
|
287
|
+
* This function evaluates an equation of the kind of the node, with the node as `self` and no capabilities. Its
|
|
288
|
+
* reads go in the list of the evaluation that made the node (READS.EQUATION).
|
|
238
289
|
*
|
|
239
290
|
* @param term - The equation.
|
|
240
291
|
* @param names - The names that the equation sees.
|
|
@@ -403,6 +454,8 @@ function plainOf(value: unknown, path: Set<object>): Result {
|
|
|
403
454
|
*/
|
|
404
455
|
function treeThing(input: EvalInput, build: TreeBuild, outer: Thing | undefined): HostThing {
|
|
405
456
|
const { parts, context, kind: type, place, machine } = input;
|
|
457
|
+
// The equations evaluate in the evaluation that made the node, thus their reads go in its list (READS.EQUATION).
|
|
458
|
+
const runtime = (input as InputWithRuntime)[RUNTIME];
|
|
406
459
|
const { tree, of } = contractOf(machine, input.typePath);
|
|
407
460
|
const above = stateOf(outer);
|
|
408
461
|
// Only a node of the same tree is a parent for the rungs `parent` and `copy`.
|
|
@@ -481,7 +534,7 @@ function treeThing(input: EvalInput, build: TreeBuild, outer: Thing | undefined)
|
|
|
481
534
|
read,
|
|
482
535
|
equation(term, names) {
|
|
483
536
|
if (machine === undefined) return fail("#NOEVAL", "The evaluation of an equation needs the machine.");
|
|
484
|
-
return equationPlan(machine, of, term)
|
|
537
|
+
return evaluateWithin(equationPlan(machine, of, term), { ...context, names, caps: NO_CAPS, self: node }, runtime);
|
|
485
538
|
},
|
|
486
539
|
childNames(child) {
|
|
487
540
|
const children = read("children");
|