@fraczak/k 8.6.1 → 8.7.1
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/CHANGELOG.md +37 -0
- package/DOCS/CODECS.md +20 -14
- package/DOCS/FILE_FORMATS.md +53 -12
- package/DOCS/GETTING_STARTED.md +15 -8
- package/DOCS/PATTERNS.md +10 -0
- package/DOCS/REPL.md +12 -7
- package/Examples/arithmetics.k +81 -468
- package/Examples/ieee-arithmetics.k +37 -33
- package/Examples/poly.k +107 -104
- package/README.md +19 -11
- package/backend-api.mjs +3 -1
- package/backends/llvm/README.md +1 -1
- package/backends/llvm/bin/k-llvm-build.mjs +5 -5
- package/backends/llvm/bin/k-llvm-compile.mjs +4 -4
- package/backends/llvm/bin/k-llvm.mjs +6 -6
- package/backends/llvm/src/cli.mjs +17 -15
- package/backends/llvm/tests/integration.sh +6 -1
- package/backends/wasm/README.md +3 -3
- package/backends/wasm/bin/k-wasm-compile.mjs +4 -4
- package/backends/wasm/bin/k-wasm.mjs +4 -4
- package/backends/wasm/src/cli.mjs +12 -10
- package/backends/wasm/src/wasm.mjs +4 -4
- package/backends/wasm/tests/integration.sh +24 -4
- package/browser/shims/fs.mjs +19 -3
- package/canonical-pattern.mjs +214 -57
- package/compiler.mjs +26 -0
- package/core.k +2 -1
- package/harness/suites/poly.mjs +14 -30
- package/index.mjs +67 -2
- package/k.mjs +14 -18
- package/kir.mjs +3 -1
- package/kvm.mjs +11 -11
- package/lib/arithmetics.k +286 -0
- package/lib/bit.k +68 -0
- package/lib/bits.k +227 -0
- package/lib/btrie.k +187 -0
- package/lib/djson.k +327 -0
- package/lib/ieee.k +709 -0
- package/lib/list.k +49 -0
- package/lib/string.k +588 -0
- package/named-patterns.mjs +2 -14
- package/object.mjs +32 -7
- package/objects/README.md +9 -3
- package/objects/compile.mjs +11 -14
- package/package.json +1 -1
- package/repl.mjs +24 -5
- package/scripts/benchmark-idempotency.mjs +22 -15
- package/scripts/benchmark.mjs +29 -10
- package/scripts/build-repl-html.mjs +41 -13
- package/scripts/perf-ieee.mjs +9 -1
- package/scripts/perf-int.mjs +10 -17
- package/scripts/perf-multiplication.mjs +9 -15
- package/scripts/perf-poly.mjs +16 -32
- package/scripts/run-tests.mjs +3 -2
- package/scripts/test-package.mjs +13 -2
- package/tests/helpers/cli.mjs +19 -3
- package/tests/integration.sh +25 -5
- package/tests/test-arithmetics.mjs +4 -2
- package/tests/test-djson-methods.mjs +21 -12
- package/tests/test-ieee-arithmetic.mjs +11 -3
- package/tests/test-ieee-text.mjs +19 -4
- package/tests/test-k-object.mjs +15 -4
- package/tests/test-karatsuba.mjs +1 -1
- package/tests/test-kvm-polymorphic.mjs +58 -34
- package/tests/test-lib.mjs +117 -0
- package/tests/test-library-isolation.mjs +381 -0
- package/tests/test-named-patterns.mjs +21 -3
- package/tests/test-parse-json.mjs +44 -14
- package/tests/test-poly.mjs +10 -4
- package/tests/test-repl-html.mjs +18 -7
- package/tests/test-repl.mjs +50 -35
- package/Examples/djson.k +0 -894
- package/Examples/ieee.k +0 -969
- package/Examples/karatsuba-mult.k +0 -227
- package/Examples/list.k +0 -10
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,43 @@ All notable changes to this project will be documented here.
|
|
|
5
5
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
6
|
This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [8.7.1] — 2026-11-08 — Content-Addressable Library Isolation and Scope Binding Fixes
|
|
9
|
+
|
|
10
|
+
- **Strict Content-Addressable Library Isolation**:
|
|
11
|
+
- Loading a library with `--lib` makes relations and pattern templates available in memory strictly by their `@<hash>`. Friendly names (aliases recorded in library metadata) never enter compilation scope by default.
|
|
12
|
+
- Fix unintended leakage of friendly names into compilation scope when importing libraries.
|
|
13
|
+
- **Explicit Scope Binding (`--use`)**:
|
|
14
|
+
- Friendly names or aliases enter compilation scope only when explicitly requested via `--use <spec>` on the CLI or `useSpecs` in the API.
|
|
15
|
+
- Preserve exact 1-to-1 source line numbers in diagnostics and AST nodes without synthetic text preambles.
|
|
16
|
+
- **Eliminate Symbol Renaming Across `lib/` Modules**:
|
|
17
|
+
- Remove all `libname:localname` aliasing colons across `lib/*.k` header comments and bodies (`inc_bits`, `list_size`, etc.).
|
|
18
|
+
- Allow standard libraries to load cleanly in the REPL (`:load`) when prerequisites are loaded in order, with zero aliasing magic.
|
|
19
|
+
- **Library Isolation Test Suite**:
|
|
20
|
+
- Add `tests/test-library-isolation.mjs` verifying relation and pattern template isolation, hash-only access, explicit `--use`, exact line numbers, and sequential REPL `:load`.
|
|
21
|
+
|
|
22
|
+
## [8.7.0] — 2026-11-07 — Standard Library Modularization and In-Memory Library Loading
|
|
23
|
+
|
|
24
|
+
- **Standard Library Modularization into `lib/`**:
|
|
25
|
+
- Reorganize core library modules from `Examples/` into a dedicated `lib/` directory:
|
|
26
|
+
- `lib/bit.k`: Basic bit, boolean, and ternary ordering schemas (`bit[]`, `bool[]`, `order[]`).
|
|
27
|
+
- `lib/bits.k`: Arbitrary-width bit sequences and 8-bit bytes (`bits[]`, `byte[]`).
|
|
28
|
+
- `lib/arithmetics.k`: Arbitrary-precision signed integers (`int[]`) and arithmetic relations.
|
|
29
|
+
- `lib/list.k`: Parametric linked lists (`list[X]`).
|
|
30
|
+
- `lib/btrie.k`: Parametric binary tries and optional values (`opt[V]`, `btrie[V]`).
|
|
31
|
+
- `lib/string.k`: ASCII bytes, Unicode codepoints, and strings (`ascii[]`, `unicode[]`, `string[]`).
|
|
32
|
+
- `lib/ieee.k`: Binary64 IEEE 754 float types and conversion (`float64[]`).
|
|
33
|
+
- `lib/djson.k`: Universal dynamic JSON schema and RFC 8259 parser (`djson[]`).
|
|
34
|
+
- Remove all hardcoded content hashes (`@hash`) from standard library source files.
|
|
35
|
+
- **In-Memory Library Loading & Dependency Comments (`# --lib ... --use ...`)**:
|
|
36
|
+
- Add leading `# --lib <dependency> --use <specs>` header comments to document library dependencies and symbol usage at the top of `.k` files without hardcoded hashes.
|
|
37
|
+
- `# --lib` lines remain strictly human-readable comments (never synthesized as text preambles), preserving exact 1-to-1 source line numbers in diagnostics, AST nodes, and warnings.
|
|
38
|
+
- `--lib <dependency.klib>` makes library relations and patterns available in memory indexed strictly by their content hashes (`@hash`); friendly names are never in scope by default.
|
|
39
|
+
- `--use <spec>` explicitly brings requested friendly names or aliases into compilation scope in memory without modifying source text or line numbers.
|
|
40
|
+
- **Toolchain & REPL Integration**:
|
|
41
|
+
- Pass `--lib` and `--use` directly into compiler options across `compileLibrary`, `compileObject`, `k.mjs`, `kvm.mjs`, LLVM, and Wasm backends.
|
|
42
|
+
- REPL `:load` brings session library definitions into scope ambiently in memory.
|
|
43
|
+
- Update all benchmarks, test harnesses, documentation, and shell pipelines to use `lib/` modules.
|
|
44
|
+
|
|
8
45
|
## [8.6.1] — 2026-11-04 — REPL `:all-patterns` and Shared-Graph Boundary Pattern Printing
|
|
9
46
|
|
|
10
47
|
- **REPL `:all-patterns` (alias `:all-pat`)**:
|
package/DOCS/CODECS.md
CHANGED
|
@@ -112,20 +112,21 @@ witness derivation. General wire semantics are specified in
|
|
|
112
112
|
| `json.mjs` / `k-json` | Document-specific schemas: objects as products, arrays as indexed products |
|
|
113
113
|
| `djson.mjs` / `k-djson` | One recursive JSON representation using binary tries for objects and arrays |
|
|
114
114
|
|
|
115
|
-
`
|
|
115
|
+
`lib/djson.k` supplies operations such as `get`, `nth`, `set`,
|
|
116
116
|
`del`, `push`, `keys`, and `values`. The specializing JSON codec and dynamic
|
|
117
117
|
JSON codec serve different schemas; they are not interchangeable encodings.
|
|
118
118
|
|
|
119
|
-
The library references
|
|
120
|
-
`
|
|
121
|
-
|
|
122
|
-
`
|
|
123
|
-
|
|
119
|
+
The library references earlier `lib/` types by their canonical hashes. Its
|
|
120
|
+
`number[]` is the IEEE `float64[]`; the sign, exponent, and fraction schemas
|
|
121
|
+
are shared too. In the REPL, load `lib/bit.k`, `lib/bits.k`, `lib/list.k`,
|
|
122
|
+
`lib/btrie.k`, `lib/string.k`, `lib/ieee.k`, then `lib/djson.k`. When
|
|
123
|
+
compiling, chain the `lib/` modules in order so each `.klib` carries forward
|
|
124
|
+
the accumulated definitions.
|
|
124
125
|
|
|
125
|
-
`
|
|
126
|
+
`lib/ieee.k` contains the binary64 representation, constructors and
|
|
126
127
|
predicates, and text conversion. Heavy add/subtract/multiply/divide definitions
|
|
127
|
-
are in `Examples/ieee-arithmetics.k`; load that file after `
|
|
128
|
-
when arithmetic is needed. JSON parsing uses
|
|
128
|
+
are in `Examples/ieee-arithmetics.k`; load that file after `lib/ieee.k`
|
|
129
|
+
when arithmetic is needed. JSON parsing uses `lib/ieee.k` alone.
|
|
129
130
|
|
|
130
131
|
`parseFloat64`: `string[]` → `float64[]` accepts JSON-style decimal syntax,
|
|
131
132
|
an optional leading `+`, surrounding ASCII JSON whitespace, and the words
|
|
@@ -145,10 +146,15 @@ surrogate escapes, and numbers that overflow to infinity are undefined.
|
|
|
145
146
|
For example, decode UTF-8 to a k string, then parse that string in k:
|
|
146
147
|
|
|
147
148
|
```sh
|
|
148
|
-
node objects/compile.mjs
|
|
149
|
-
node objects/compile.mjs --lib /tmp/
|
|
149
|
+
node objects/compile.mjs lib/bit.k /tmp/bit.klib
|
|
150
|
+
node objects/compile.mjs --lib /tmp/bit.klib lib/bits.k /tmp/bits.klib
|
|
151
|
+
node objects/compile.mjs --lib /tmp/bits.klib lib/list.k /tmp/list.klib
|
|
152
|
+
node objects/compile.mjs --lib /tmp/list.klib lib/btrie.k /tmp/btrie.klib
|
|
153
|
+
node objects/compile.mjs --lib /tmp/btrie.klib lib/string.k /tmp/string.klib
|
|
154
|
+
node objects/compile.mjs --lib /tmp/string.klib lib/ieee.k /tmp/ieee.klib
|
|
155
|
+
node objects/compile.mjs --lib /tmp/ieee.klib lib/djson.k /tmp/djson.klib
|
|
150
156
|
printf '%s' '{"answer":42}' | node codecs/utf8.mjs --parse |
|
|
151
|
-
node k.mjs --lib /tmp/djson.klib --
|
|
157
|
+
node k.mjs --lib /tmp/djson.klib --use parseJson 'parseJson' |
|
|
152
158
|
node codecs/djson.mjs --print
|
|
153
159
|
```
|
|
154
160
|
|
|
@@ -160,14 +166,14 @@ The compiled IEEE library also supports a complete text round-trip in k:
|
|
|
160
166
|
|
|
161
167
|
```sh
|
|
162
168
|
printf '%s' '1.5' | node codecs/utf8.mjs --parse |
|
|
163
|
-
node k.mjs --lib /tmp/ieee
|
|
169
|
+
node k.mjs --lib /tmp/ieee.klib --use parseFloat64 --use printFloat64 'parseFloat64 printFloat64' |
|
|
164
170
|
node codecs/utf8.mjs --print
|
|
165
171
|
```
|
|
166
172
|
|
|
167
173
|
For arithmetic, compile the optional layer against the same IEEE library:
|
|
168
174
|
|
|
169
175
|
```sh
|
|
170
|
-
node objects/compile.mjs --lib /tmp/ieee
|
|
176
|
+
node objects/compile.mjs --lib /tmp/ieee.klib Examples/ieee-arithmetics.k /tmp/ieee-arithmetics.klib
|
|
171
177
|
```
|
|
172
178
|
|
|
173
179
|
`k-parse` and `k-print` use [textual k values](TEXTUAL_VALUES.md), rather than
|
package/DOCS/FILE_FORMATS.md
CHANGED
|
@@ -58,7 +58,7 @@ given. `-o` / `--output` is an alternative to the positional output path.
|
|
|
58
58
|
|
|
59
59
|
```sh
|
|
60
60
|
node objects/compile.mjs 'greet = {} |hello;' /tmp/k-demo.klib
|
|
61
|
-
node objects/compile.mjs --lib /tmp/k-demo.klib --
|
|
61
|
+
node objects/compile.mjs --lib /tmp/k-demo.klib --use greet 'greet' /tmp/k-greet.ko
|
|
62
62
|
node codecs/unit.mjs --parse | node k.mjs /tmp/k-greet.ko |
|
|
63
63
|
node codecs/k-print.mjs
|
|
64
64
|
```
|
|
@@ -67,23 +67,64 @@ This prints `"hello"`. `--lib` loads a dependency; it does not select library
|
|
|
67
67
|
output. These are equivalent ways to generate a library from source:
|
|
68
68
|
|
|
69
69
|
```sh
|
|
70
|
-
node objects/compile.mjs
|
|
71
|
-
node objects/compile.mjs --
|
|
70
|
+
node objects/compile.mjs lib/bit.k /tmp/bit.klib
|
|
71
|
+
node objects/compile.mjs --lib /tmp/bit.klib lib/bits.k /tmp/bits.klib
|
|
72
|
+
node objects/compile.mjs --lib /tmp/bits.klib lib/arithmetics.k /tmp/k-math.klib
|
|
72
73
|
```
|
|
73
74
|
|
|
74
|
-
Only one `--lib` is accepted
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
`--export` for each needed alias. Source can reference hashes directly.
|
|
75
|
+
Only one `--lib` is accepted on the command line by current CLI tools. Chained
|
|
76
|
+
libraries carry forward definitions from their predecessors, so compiling a
|
|
77
|
+
series of libraries extends the environment cumulatively.
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
### Source header comments (`# --lib ... --use ...`)
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
To clearly document dependencies and recommended compilation options without scattering hardcoded content hashes (`@hash`) throughout source code, `.k` files declare their library dependencies and imported symbols using header comments at the very top of the file:
|
|
82
|
+
|
|
83
|
+
```k
|
|
84
|
+
# --lib <dependency-path> --use <spec1> <spec2> ...
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### Syntax & Convention
|
|
88
|
+
|
|
89
|
+
1. **Placement**: Comments appear in the first comment block at the very top of the file, before any relation or pattern definitions.
|
|
90
|
+
2. **Comment prefix**: Lines start with `# --lib`. Because `#` is a standard one-line comment character in k, the line is fully valid k syntax and is treated purely as a comment. It is **not** an active compiler directive.
|
|
91
|
+
3. **Target library**: `<dependency-path>` indicates the library providing the symbols (for example, `lib/bits.k` or `lib/string.k`).
|
|
92
|
+
4. **Symbol specs**: `--use` lists the symbols used from the library:
|
|
93
|
+
- `name`: references a library relation or pattern under the same name.
|
|
94
|
+
- `libname:localname`: aliases a library relation or pattern `libname` under a local name `localname`.
|
|
95
|
+
- `pattern[Params]`: references a named pattern with its parameter signature (e.g. `btrie[V]` or `byte[]`).
|
|
96
|
+
- `pattern[Params]:localname[Params]`: aliases a named pattern under a local name (e.g. `float64[]:number[]`).
|
|
97
|
+
|
|
98
|
+
Multiple `# --lib` lines can be declared to document multiple dependencies:
|
|
99
|
+
|
|
100
|
+
```k
|
|
101
|
+
# --lib lib/bits.k --use trim inv_loop inv cmp inc_bits dec_bits plus_bits minus_bits mul_bits
|
|
85
102
|
```
|
|
86
103
|
|
|
104
|
+
#### How `--lib` and `--use` Work
|
|
105
|
+
|
|
106
|
+
When source code is compiled with library dependencies (`k-compile`, `k.mjs`, `compileLibrary`, `compileObject`, or the REPL's `:load`):
|
|
107
|
+
|
|
108
|
+
1. **Content-Addressed Availability (Hash-Only)**: When `--lib file.klib` is supplied, all relations and patterns defined in the library are available in memory indexed strictly by their content hashes (`@<hash>`). Friendly names (the aliases recorded in library metadata) are **never** in scope by default.
|
|
109
|
+
2. **Explicit Symbol Scope (`--use`)**: To bring a library relation or pattern into scope under a friendly name, `--use <spec>` must be specified (or `useSpecs` passed in the compiler API). The compiler resolves the spec against the library's metadata aliases and binds the friendly or aliased name directly in the in-memory symbol tables.
|
|
110
|
+
3. **No Automatic Ingestion or Precedence Ambiguity**: Because library friendly names are not in scope without `--use`, there is no implicit shadowing or "precedence". Local definitions define local names; library definitions are accessed by `@<hash>` or by the names explicitly brought into scope via `--use`.
|
|
111
|
+
4. **No Text Synthesis or Line Offset**: The compiler never synthesizes source code or prepends preamble text to user files. Source text remains completely untouched, preserving exact 1-to-1 line numbers in AST nodes, diagnostics, warnings, and error messages.
|
|
112
|
+
|
|
113
|
+
#### Command-Line Usage
|
|
114
|
+
|
|
115
|
+
- Compile a file using a pre-compiled library and explicit `--use` bindings (as documented in the file's header comments):
|
|
116
|
+
```sh
|
|
117
|
+
node objects/compile.mjs --lib /tmp/bits.klib \
|
|
118
|
+
--use "trim inv_loop inv cmp inc_bits dec_bits plus_bits minus_bits mul_bits" \
|
|
119
|
+
lib/arithmetics.k /tmp/arithmetics.klib
|
|
120
|
+
```
|
|
121
|
+
- Command-line `--use spec` flags bring relations into scope for evaluation:
|
|
122
|
+
```sh
|
|
123
|
+
printf '42\n' | node codecs/int.mjs --parse |
|
|
124
|
+
node k.mjs --lib /tmp/k-math.klib --use inc 'inc' |
|
|
125
|
+
node codecs/int.mjs --print
|
|
126
|
+
```
|
|
127
|
+
|
|
87
128
|
This prints `43`. Numeral names such as `5` in the arithmetic library are
|
|
88
129
|
relations producing bit trees. `5 int` constructs a signed integer; numeral
|
|
89
130
|
names are not builtin literals.
|
package/DOCS/GETTING_STARTED.md
CHANGED
|
@@ -117,10 +117,12 @@ constraints. Derivation convergence does not prove that every program terminates
|
|
|
117
117
|
|
|
118
118
|
## Libraries and external numbers
|
|
119
119
|
|
|
120
|
-
Load the integer library and a codec explicitly:
|
|
120
|
+
Load the integer library chain and a codec explicitly:
|
|
121
121
|
|
|
122
122
|
```text
|
|
123
|
-
:load
|
|
123
|
+
:load lib/bit.k
|
|
124
|
+
:load lib/bits.k
|
|
125
|
+
:load lib/arithmetics.k
|
|
124
126
|
:codec load codecs/int.mjs
|
|
125
127
|
:input int.mjs 42
|
|
126
128
|
```
|
|
@@ -128,13 +130,13 @@ Load the integer library and a codec explicitly:
|
|
|
128
130
|
Now evaluate `inc` to obtain 43. The codec prints the decimal representation
|
|
129
131
|
alongside the structural value.
|
|
130
132
|
|
|
131
|
-
For list operations, load
|
|
133
|
+
For list operations, load `lib/list.k` and `Examples/poly.k`:
|
|
132
134
|
|
|
133
135
|
```text
|
|
136
|
+
:load lib/list.k
|
|
134
137
|
:load Examples/poly.k
|
|
135
138
|
```
|
|
136
139
|
|
|
137
|
-
For a smaller self-contained list example, use `:load Examples/list.k`.
|
|
138
140
|
See the [REPL guide](REPL.md) for loading, pattern inspection, and exports.
|
|
139
141
|
|
|
140
142
|
## Shell pipelines
|
|
@@ -143,14 +145,19 @@ The command-line runtime receives binary schema+payload data, so use codecs
|
|
|
143
145
|
at text boundaries. From the repository root:
|
|
144
146
|
|
|
145
147
|
```sh
|
|
148
|
+
node objects/compile.mjs lib/bit.k /tmp/bit.klib
|
|
149
|
+
node objects/compile.mjs --lib /tmp/bit.klib lib/bits.k /tmp/bits.klib
|
|
150
|
+
node objects/compile.mjs --lib /tmp/bits.klib lib/arithmetics.k /tmp/arithmetics.klib
|
|
146
151
|
printf '42\n' | node codecs/int.mjs --parse |
|
|
147
|
-
node k.mjs --lib
|
|
152
|
+
node k.mjs --lib /tmp/arithmetics.klib --use inc 'inc' |
|
|
148
153
|
node codecs/int.mjs --print
|
|
149
154
|
```
|
|
150
155
|
|
|
151
|
-
This prints `43`.
|
|
152
|
-
|
|
153
|
-
|
|
156
|
+
This prints `43`. When compiling with `--lib /tmp/bits.klib`, all definitions
|
|
157
|
+
from the library are available in memory during compilation.
|
|
158
|
+
For ad-hoc expressions on the CLI, `--use inc` brings the library relation
|
|
159
|
+
into scope under a local alias. Library relations and patterns are also
|
|
160
|
+
accessible by their canonical content hashes.
|
|
154
161
|
|
|
155
162
|
To compile a small executable object and run it:
|
|
156
163
|
|
package/DOCS/PATTERNS.md
CHANGED
|
@@ -36,6 +36,16 @@ Relations can refer to other definitions in the same source, including recursive
|
|
|
36
36
|
references. Labels can be identifiers or quoted strings with escapes. Line
|
|
37
37
|
comments use `--`, `//`, `#`, or `%`; block comments use `/* ... */`.
|
|
38
38
|
|
|
39
|
+
### Source header comments and library dependencies
|
|
40
|
+
|
|
41
|
+
Files document their library dependencies and imported symbols using header comments at the very top of the file:
|
|
42
|
+
|
|
43
|
+
```k
|
|
44
|
+
# --lib <dependency-path> --use <spec1> <spec2> ...
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Because `#` is a standard line comment character in k, these lines are valid k syntax and remain purely comments. They document the dependency relations for readers and build tools. When compiling with `--lib`, definitions from the library are available in memory by their content hashes (`@<hash>`), and `--use` brings requested friendly names or aliases into the local compilation scope. See [file formats and tools](FILE_FORMATS.md#source-header-comments---lib-----use---) for complete details.
|
|
48
|
+
|
|
39
49
|
## Pattern syntax
|
|
40
50
|
|
|
41
51
|
Patterns describe schema constraints rather than computations:
|
package/DOCS/REPL.md
CHANGED
|
@@ -48,17 +48,22 @@ Regular evaluations include timing; there is no separate timing command.
|
|
|
48
48
|
## Loading and aliases
|
|
49
49
|
|
|
50
50
|
```text
|
|
51
|
-
:load
|
|
51
|
+
:load lib/bit.k
|
|
52
|
+
:load lib/bits.k
|
|
53
|
+
:load lib/arithmetics.k
|
|
54
|
+
:load lib/list.k
|
|
52
55
|
:load Examples/poly.k
|
|
53
56
|
```
|
|
54
57
|
|
|
55
58
|
Libraries are loaded explicitly. `poly.k` depends on definitions in
|
|
56
|
-
`arithmetics.k`, so load them in
|
|
57
|
-
automatically load its corresponding k library.
|
|
59
|
+
`lib/arithmetics.k` and `lib/list.k`, so load them in dependency order. Loading
|
|
60
|
+
a codec does not automatically load its corresponding k library.
|
|
58
61
|
|
|
59
62
|
`:load` compiles a `.k` file in the current library context or loads a plain
|
|
60
|
-
JSON `.klib`.
|
|
61
|
-
|
|
63
|
+
JSON `.klib`. All relations and patterns in the current session library context
|
|
64
|
+
are available in memory during compilation. It recovers relation and pattern aliases
|
|
65
|
+
unless `--no-alias` is specified. Source libraries' terminal expressions are not
|
|
66
|
+
run by `:load`.
|
|
62
67
|
|
|
63
68
|
Names are local aliases for canonical definitions. Rebinding a relation alias
|
|
64
69
|
leaves older definitions addressable by hash in the live session.
|
|
@@ -90,8 +95,8 @@ See [patterns and canonical identity](PATTERNS.md).
|
|
|
90
95
|
inc
|
|
91
96
|
```
|
|
92
97
|
|
|
93
|
-
Load `
|
|
94
|
-
integer value; the library supplies the relation.
|
|
98
|
+
Load `lib/bit.k`, `lib/bits.k`, and `lib/arithmetics.k` before using `inc`.
|
|
99
|
+
The codec supplies the integer value; the library supplies the relation.
|
|
95
100
|
|
|
96
101
|
Codecs export `parse` and `print`. Input uses the codec explicitly selected
|
|
97
102
|
with `:input`. When the text is omitted, the next line is parsed as external
|