@mark1russell7/coeval 0.1.0 → 0.2.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 ADDED
@@ -0,0 +1,41 @@
1
+ # @mark1russell7/coeval
2
+
3
+ The kernel of coeval: a base for declarative languages. A program is a JSON document in an envelope, `{ type, value }`. The kind of the document names its evaluator, and a ladder finds it. A language evaluates through this kernel and keeps only what is its own.
4
+
5
+ ```sh
6
+ npm install @mark1russell7/coeval
7
+ ```
8
+
9
+ ## A formula language in a few lines
10
+
11
+ ```ts
12
+ import { context, formulaMachine, prepare } from "@mark1russell7/coeval";
13
+
14
+ const machine = formulaMachine({ ops: { add: (a: number, b: number) => a + b } });
15
+ const doc = { type: ["ops", "add"], value: [{ type: "ref", value: ["names", "x"] }, 1] };
16
+
17
+ const plan = prepare(machine, doc); // the ladder, the kinds and the parts, one time
18
+ plan.evaluate(context({ names: { x: 2 } })); // { ok: true, value: 3 }
19
+ ```
20
+
21
+ A plan evaluates many times without a trace. `evaluate(machine, doc)` gives the same result with a full trace, for a debugger or an explanation.
22
+
23
+ ## What the kernel holds
24
+
25
+ | Part | Exports | What it does |
26
+ | --- | --- | --- |
27
+ | Documents | `isEnvelope`, `stored`, `typePath`, `docEquals` | The envelope, the keys of a store beside it, and the equality of documents |
28
+ | World | `lookupKind`, `Kind`, `Namespace`, `PartShape`, `ScopeRule` | The kinds, with their contracts: the shape of the parts, the names that a kind binds, and its effects. A namespace can have a fallback kind |
29
+ | Ladder | `ask` | The evaluator of a verb: the own entry, then the kind, then the default |
30
+ | References | `resolve`, `HostThing`, `Navigator` | A path from a root of the context: `self`, `names`, `world`, `event` or `caps` |
31
+ | Plans | `prepare`, `planner`, `evaluate`, `run` | A document compiles one time into code. An evaluator is a function or a compiler |
32
+ | The run side | `run`, `Runner`, `permits`, `narrow` | Effects in order, parts at the same time, capabilities that only narrow, and an abort |
33
+ | Errors | `Result`, `EvalError`, `Failure`, `failures` | An error value has a code, a reason, a place and a cause. An evaluation does not throw |
34
+ | The static kit | `walk`, `refsOf`, `mapRefs`, `check` | The documents of a document, its free references, and its problems before a run |
35
+ | The formula kit | `formulaMachine`, `FormulaProfile` | The shared constructs `lit`, `ref`, `record`, `list`, `let`, `fn`, `call`, `if`, `and`, `or`, and the namespaces `ops` and `ext` |
36
+
37
+ Each rule has an ID in [`docs/SPEC.md`](https://github.com/mark1russell7/coeval/blob/main/docs/SPEC.md), and each ID has a test. [The site](https://mark1russell7.github.io/coeval/) explains each idea with a live diagram.
38
+
39
+ ## License
40
+
41
+ MIT