@fraczak/k 6.0.4 → 6.1.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/AGENTS.md +2 -2
- package/CHANGELOG.md +22 -5
- package/CLAUDE.md +4 -4
- package/DOCS/BIG_PICTURE.md +5 -5
- package/DOCS/BINARY_CODEC_STATUS_AND_TODO.md +3 -3
- package/DOCS/OBJECT_FILE_AND_PATTERN.md +9 -9
- package/DOCS/PATTERNS.md +6 -5
- package/DOCS/REPL.md +2 -2
- package/DOCS/book/06-values-in-memory.md +1 -1
- package/DOCS/book.md +20 -24
- package/README.md +200 -274
- package/codecs/README.md +21 -2
- package/codecs/example-pipeline.mjs +14 -0
- package/codecs/ieee.mjs +13 -3
- package/codecs/int.mjs +13 -3
- package/codecs/json.mjs +13 -3
- package/codecs/k-parse.mjs +5 -0
- package/codecs/k-print.mjs +16 -1
- package/codecs/show.mjs +15 -1
- package/codecs/unit.mjs +13 -3
- package/codecs/utf16.mjs +13 -3
- package/codecs/utf8.mjs +13 -3
- package/k-vscode/README.md +3 -2
- package/k.mjs +9 -1
- package/objects/README.md +11 -8
- package/package.json +13 -7
- package/{repl2.mjs → repl.mjs} +19 -0
- package/{test-repl2.mjs → test-repl.mjs} +4 -4
package/AGENTS.md
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
- `npm install` installs dev dependencies and runs `prepare` to generate parsers.
|
|
12
12
|
- `npm run prepare` regenerates `parser.mjs` and `valueParser.mjs` from `.jison` grammars.
|
|
13
13
|
- `npm test` runs the full suite (`test.mjs`, `Code-derivation-tests/*.mjs`, `test-fingerprint.mjs`, `tests.sh`).
|
|
14
|
-
- `node
|
|
15
|
-
- `./k.mjs <file.k>` executes a k script on binary pattern+value stream input from stdin or a file; use `k-parse` and `k-print` at the boundaries.
|
|
14
|
+
- `node repl.mjs` (or `k-repl`) starts the interactive REPL.
|
|
15
|
+
- `./k.mjs -k <file.k>` executes a k script on binary pattern+value stream input from stdin or a file; use `k-parse` and `k-print` at the boundaries.
|
|
16
16
|
|
|
17
17
|
## Coding Style & Naming Conventions
|
|
18
18
|
- JavaScript uses ES modules (`.mjs`) with 2-space indentation and semicolons.
|
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,22 @@ This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
+
## [6.1.0] — 2026-05-20 — CLI aliases and help
|
|
11
|
+
|
|
12
|
+
### Toolchain
|
|
13
|
+
|
|
14
|
+
- Renamed the REPL entry point to `repl.mjs` and the installed binary to `k-repl`.
|
|
15
|
+
- Unified installed command names around the `k-` prefix and source basenames.
|
|
16
|
+
- Added `-h` / `--help` support across executable CLI scripts.
|
|
17
|
+
- Added public aliases in `Examples/ieee.k` for `add`, `sub`, `mul`, `div`, comparisons, and `neg`.
|
|
18
|
+
|
|
19
|
+
### Documentation
|
|
20
|
+
|
|
21
|
+
- Reworked the README around typed data transformations, contributor entry points, and the IEEE example.
|
|
22
|
+
- Updated CLI references across documentation to the current installed command names.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
10
26
|
## [6.0.0] — 2026-05-12 — First public release
|
|
11
27
|
|
|
12
28
|
### Language & Runtime
|
|
@@ -22,18 +38,18 @@ This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
22
38
|
- Finite tree automaton type representation (`codes.mjs`).
|
|
23
39
|
- Graph-based constraint propagation via `TypePatternGraph`.
|
|
24
40
|
- SCC-aware convergence with configurable strategy (`auto` / `single_pass` / `fixed_point`).
|
|
25
|
-
- `compileStats` API for inspecting convergence
|
|
41
|
+
- `compileStats` API for inspecting convergence behavior per SCC.
|
|
26
42
|
|
|
27
43
|
### Toolchain
|
|
28
44
|
|
|
29
45
|
- `k` — CLI executor: reads binary pattern+value stream, applies a k script, writes result.
|
|
30
|
-
- `k-repl`
|
|
31
|
-
- `k-
|
|
32
|
-
- `k-compile-
|
|
46
|
+
- `k-repl` — interactive interpreter with tab-completion.
|
|
47
|
+
- `k-compile` / `k-decompile` — object file compilation and decompilation.
|
|
48
|
+
- `k-compile-lib` / `k-extract-aliases` — library compilation and alias extraction.
|
|
33
49
|
|
|
34
50
|
### Codec Pipeline
|
|
35
51
|
|
|
36
|
-
- Binary format:
|
|
52
|
+
- Binary format: serialized pattern graph followed by value encoded under that pattern.
|
|
37
53
|
- JSON codec, UTF-8/UTF-16 string codec, IEEE 754 codec.
|
|
38
54
|
- Polymorphic codec streams: pattern carried in-memory through projections and constructors.
|
|
39
55
|
|
|
@@ -45,4 +61,5 @@ This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
45
61
|
|
|
46
62
|
---
|
|
47
63
|
|
|
64
|
+
[6.1.0]: https://github.com/fraczak/k/releases/tag/v6.1.0
|
|
48
65
|
[6.0.0]: https://github.com/fraczak/k/releases/tag/v6.0.0
|
package/CLAUDE.md
CHANGED
|
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
|
|
4
4
|
|
|
5
5
|
## Project Overview
|
|
6
6
|
|
|
7
|
-
k
|
|
7
|
+
k is an experimental language for describing algebraic data shapes and composing typed transformations over them. Data descriptions and transformations share one syntax; the native k-like notation is canonical, and a JSON-like notation is available as a convenience for textual values.
|
|
8
8
|
|
|
9
9
|
## Essential Commands
|
|
10
10
|
|
|
@@ -20,8 +20,8 @@ npm test # Run comprehensive test suite (unit tests, derivation tests, shell te
|
|
|
20
20
|
|
|
21
21
|
**Running k programs:**
|
|
22
22
|
```bash
|
|
23
|
-
./k.mjs <file.k>
|
|
24
|
-
./
|
|
23
|
+
./k.mjs -k <file.k> # Execute k script
|
|
24
|
+
./repl.mjs # Start interactive REPL (or: k-repl)
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
## Architecture
|
|
@@ -61,4 +61,4 @@ npm test # Run comprehensive test suite (unit tests, derivation tests, shell te
|
|
|
61
61
|
- No external runtime dependencies (only jiwson for parser generation)
|
|
62
62
|
- Uses ES6 modules (.mjs files) throughout
|
|
63
63
|
- Extensive test suite in `Code-derivation-tests/` for type system validation
|
|
64
|
-
- REPL supports commands like
|
|
64
|
+
- REPL supports commands like `:C name` (show canonical type), `:t name` (show relation type), and `:d name` (show relation definition)
|
package/DOCS/BIG_PICTURE.md
CHANGED
|
@@ -82,7 +82,7 @@ filter_label_list ::= /* empty */ | '...'
|
|
|
82
82
|
|
|
83
83
|
Examples:
|
|
84
84
|
|
|
85
|
-
```
|
|
85
|
+
```text
|
|
86
86
|
X -- any type
|
|
87
87
|
( ... ) -- any type
|
|
88
88
|
{ ... } -- any product type
|
|
@@ -178,7 +178,7 @@ The normalization steps are:
|
|
|
178
178
|
|
|
179
179
|
#### Example 1
|
|
180
180
|
|
|
181
|
-
```
|
|
181
|
+
```text
|
|
182
182
|
$ bit = < {} o, {} i >;
|
|
183
183
|
bit0 = | o $bit;
|
|
184
184
|
bit1 = | i $bit;
|
|
@@ -242,7 +242,7 @@ Such a pattern is called _singleton pattern_, as only one type fits the pattern.
|
|
|
242
242
|
|
|
243
243
|
Polymorphic list functions:
|
|
244
244
|
|
|
245
|
-
```
|
|
245
|
+
```text
|
|
246
246
|
list? = ?< {} nil, {X car, Y cdr} cons > = Y;
|
|
247
247
|
nil = {} |nil list?;
|
|
248
248
|
singleton = {() car, nil cdr} |cons list?;
|
|
@@ -254,7 +254,7 @@ cdr = list? /cons .cdr;
|
|
|
254
254
|
|
|
255
255
|
For example, the filter annotation for `car` is:
|
|
256
256
|
|
|
257
|
-
```
|
|
257
|
+
```text
|
|
258
258
|
> :t car
|
|
259
259
|
car : ?<{X1 car, X0 cdr} cons, $KL nil>=X0 --> ?X1 (@...)
|
|
260
260
|
> :C KL
|
|
@@ -301,7 +301,7 @@ A type can be translated into a Rust data structure, and a function can be trans
|
|
|
301
301
|
|
|
302
302
|
Extending `@string` into `@bits`.
|
|
303
303
|
|
|
304
|
-
```
|
|
304
|
+
```text
|
|
305
305
|
$ bits = < {} _, bits 0, bits 1 >;
|
|
306
306
|
```
|
|
307
307
|
|
|
@@ -51,9 +51,9 @@ value-payload DAG compression.
|
|
|
51
51
|
|
|
52
52
|
```bash
|
|
53
53
|
echo '["zebara", "ela", "kupa", ala, owca]' | \
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
k-parse | \
|
|
55
|
+
k '{.1 0,.3 1}' | \
|
|
56
|
+
k-print
|
|
57
57
|
```
|
|
58
58
|
|
|
59
59
|
Expected output:
|
|
@@ -133,7 +133,7 @@ Loading an object hydrates the type-pattern graphs back into runtime
|
|
|
133
133
|
Object execution through `k.mjs`:
|
|
134
134
|
|
|
135
135
|
```sh
|
|
136
|
-
echo "..." |
|
|
136
|
+
echo "..." | some-codec --parse | k -k path/to/program.ko | some-codec --print
|
|
137
137
|
```
|
|
138
138
|
|
|
139
139
|
The `-k` option accepts either an object file or a source `.k` file. `k.mjs`
|
|
@@ -143,17 +143,17 @@ compilation.
|
|
|
143
143
|
Standalone helpers live in `objects/`:
|
|
144
144
|
|
|
145
145
|
```sh
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
146
|
+
k-compile path/to/program.k path/to/program.ko
|
|
147
|
+
k-compile-lib path/to/library.k path/to/library.klib
|
|
148
|
+
k-decompile path/to/program.ko path/to/program.decompiled.k
|
|
149
|
+
k-extract-aliases path/to/library.klib path/to/aliases.k
|
|
150
150
|
```
|
|
151
151
|
|
|
152
152
|
With no arguments, the helpers read from stdin and write to stdout:
|
|
153
153
|
|
|
154
154
|
```sh
|
|
155
|
-
cat path/to/program.k |
|
|
156
|
-
cat path/to/program.ko |
|
|
155
|
+
cat path/to/program.k | k-compile > path/to/program.ko
|
|
156
|
+
cat path/to/program.ko | k-decompile > path/to/program.decompiled.k
|
|
157
157
|
```
|
|
158
158
|
|
|
159
159
|
The decompiled source is canonical source regenerated from object IR. It uses
|
|
@@ -173,7 +173,7 @@ For a tiny source file:
|
|
|
173
173
|
compile it with:
|
|
174
174
|
|
|
175
175
|
```sh
|
|
176
|
-
|
|
176
|
+
k-compile id.k id.ko
|
|
177
177
|
```
|
|
178
178
|
|
|
179
179
|
The first bytes of `id.ko` are the binary container header:
|
|
@@ -259,7 +259,7 @@ succ = |succ;
|
|
|
259
259
|
compile it with:
|
|
260
260
|
|
|
261
261
|
```sh
|
|
262
|
-
|
|
262
|
+
k-compile-lib defs.k defs.klib
|
|
263
263
|
```
|
|
264
264
|
|
|
265
265
|
The output file is plain JSON and starts with `{`, not a binary prefix. Its
|
package/DOCS/PATTERNS.md
CHANGED
|
@@ -66,9 +66,10 @@ list
|
|
|
66
66
|
|
|
67
67
|
In both cases, the compiler derives a root pattern from `__main__`.
|
|
68
68
|
|
|
69
|
-
##
|
|
69
|
+
## Pattern Export Helper
|
|
70
70
|
|
|
71
|
-
`k
|
|
71
|
+
`patterns/from-k.mjs` extracts that root pattern from a k script. It is a
|
|
72
|
+
repository helper, not an installed `package.json` binary.
|
|
72
73
|
|
|
73
74
|
It:
|
|
74
75
|
|
|
@@ -84,7 +85,7 @@ It:
|
|
|
84
85
|
Example:
|
|
85
86
|
|
|
86
87
|
```bash
|
|
87
|
-
echo '?< {} nil, { $bits car, X cdr } cons > = X' | k
|
|
88
|
+
echo '?< {} nil, { $bits car, X cdr } cons > = X' | node ./patterns/from-k.mjs
|
|
88
89
|
```
|
|
89
90
|
|
|
90
91
|
Typical output:
|
|
@@ -101,8 +102,8 @@ The active wire format is:
|
|
|
101
102
|
encode($pattern_value : $pattern) encode(value : decoded_pattern)
|
|
102
103
|
```
|
|
103
104
|
|
|
104
|
-
So the property-list array printed by `k
|
|
105
|
-
of the same pattern information carried in the wire stream.
|
|
105
|
+
So the property-list array printed by `patterns/from-k.mjs` is a readable
|
|
106
|
+
externalization of the same pattern information carried in the wire stream.
|
|
106
107
|
|
|
107
108
|
`k-parse --input-pattern ...` and `k-parse --input-type ...` both ultimately
|
|
108
109
|
produce the same kind of root pattern used to interpret textual values.
|
package/DOCS/REPL.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# k Interpreter
|
|
2
2
|
|
|
3
|
-
`
|
|
4
|
-
start it
|
|
3
|
+
`repl.mjs` is the interactive k interpreter. After linking or installing the
|
|
4
|
+
package, start it with `k-repl`.
|
|
5
5
|
|
|
6
6
|
The interpreter keeps a live `.klib`-style state in memory:
|
|
7
7
|
|
|
@@ -113,7 +113,7 @@ Each node in the value tree is encoded based on its automaton state:
|
|
|
113
113
|
|
|
114
114
|
For type `bnat`, intuitively binary natural numbers defined by `$bnat = < bnat 0, bnat 1, {} _ >`, we get
|
|
115
115
|
|
|
116
|
-
```
|
|
116
|
+
```text
|
|
117
117
|
> :C bnat
|
|
118
118
|
$ bnat = < @... 0, @... 1, {} _ >; -- @...
|
|
119
119
|
```
|
package/DOCS/book.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "k
|
|
2
|
+
title: "k"
|
|
3
3
|
author: "W. Fraczak"
|
|
4
4
|
---
|
|
5
5
|
|
|
@@ -15,32 +15,28 @@ author: "W. Fraczak"
|
|
|
15
15
|
|
|
16
16
|
</div>
|
|
17
17
|
|
|
18
|
-
# The k
|
|
19
|
-
|
|
20
|
-
This book describes the k programming language
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
14. [Canonical Serialization](book/14-canonical-serialization.md)
|
|
38
|
-
15. [Optimization and Folding](book/15-optimization-and-folding.md)
|
|
39
|
-
16. [Toward a Universal Schema Registry](book/16-toward-a-universal-schema-registry.md)
|
|
18
|
+
# The k Book
|
|
19
|
+
|
|
20
|
+
This book describes the k programming language: a minimal functional language
|
|
21
|
+
for transforming tree-structured data using partial functions and algebraic
|
|
22
|
+
data types.
|
|
23
|
+
|
|
24
|
+
## Available Chapters
|
|
25
|
+
|
|
26
|
+
- [Introduction](book/01-introduction.md)
|
|
27
|
+
- [Syntax and Values](book/02-syntax-and-values.md)
|
|
28
|
+
- [Types as Finite Automata](book/03-types-as-finite-automata.md)
|
|
29
|
+
- [Partial Functions and Composition](book/04-partial-functions-and-composition.md)
|
|
30
|
+
- [Typing, Filters, and Normalization](book/05-typing-filters-and-normalization.md)
|
|
31
|
+
- [Values in Memory](book/06-values-in-memory.md)
|
|
32
|
+
- [The Partial Function ABI](book/07-the-partial-function-abi.md)
|
|
33
|
+
- [Operational Semantics and Execution](book/08-operational-semantics-and-execution.md)
|
|
34
|
+
- [Compiler Architecture](book/09-compiler-architecture.md)
|
|
35
|
+
- [From AST to Intermediate Representation](book/10-from-ast-to-intermediate-representation.md)
|
|
36
|
+
- [Canonical Serialization](book/14-canonical-serialization.md)
|
|
40
37
|
|
|
41
38
|
## Appendices
|
|
42
39
|
|
|
43
|
-
- [Appendix A: Implementing a Prototype Compiler in Python](book/appendix-a-implementing-a-prototype-compiler-in-python.md)
|
|
44
40
|
- [Appendix B: Incorporating External Predefined Types and Functions](book/appendix-b-incorporating-external-predefined-types-and-functions.md)
|
|
45
41
|
|
|
46
42
|
---
|