@fraczak/k 6.8.0 → 6.9.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/CHANGELOG.md +10 -0
- package/DOCS/CODECS.md +80 -181
- package/DOCS/CODEC_ARCHITECTURE.md +194 -0
- package/DOCS/REPL.md +41 -39
- package/Examples/arithmetics.k +1 -0
- package/Examples/poly.k +46 -0
- package/browser/repl-browser.mjs +109 -782
- package/browser/shims/process.mjs +7 -0
- package/browser/tree-view.mjs +5 -2
- package/browser/vfs-data.mjs +14 -14
- package/codecs/README.md +7 -0
- package/codecs/ieee.mjs +50 -75
- package/codecs/int.mjs +83 -62
- package/codecs/json-codec.mjs +5 -77
- package/codecs/json.mjs +12 -56
- package/codecs/k-parse.mjs +3 -19
- package/codecs/runtime/codec-sdk.mjs +94 -0
- package/codecs/runtime/pattern-k.mjs +45 -0
- package/codecs/string-codec.mjs +48 -74
- package/codecs/unit.mjs +13 -61
- package/codecs/utf16.mjs +13 -56
- package/codecs/utf8.mjs +11 -55
- package/package.json +1 -1
- package/patterns/from-k.mjs +2 -22
- package/repl-codecs.mjs +69 -196
- package/repl.mjs +63 -187
- package/scripts/build-repl-html.mjs +87 -379
- package/scripts/run-tests.mjs +1 -0
- package/tests/test-codecs.mjs +186 -0
- package/tests/test-poly.mjs +44 -0
- package/tests/test-repl-html.mjs +123 -64
- package/tests/test-repl.mjs +120 -134
- package/tests/test-structural-values.mjs +17 -0
- package/tests/test-tree-view.mjs +3 -0
- package/codecs/example-pipeline.mjs +0 -163
- package/codecs/runtime/ieee-pattern.mjs +0 -30
- package/codecs/runtime/test-codec.mjs +0 -89
- package/codecs/runtime/typeFromValue.mjs +0 -34
package/Examples/arithmetics.k
CHANGED
package/Examples/poly.k
CHANGED
|
@@ -65,3 +65,49 @@ zip = <
|
|
|
65
65
|
{.xs cdr xs, .ys cdr ys} zip cdr
|
|
66
66
|
} cons
|
|
67
67
|
>;
|
|
68
|
+
|
|
69
|
+
-- Gen list of intgers: n -> [0, 1, ..., n]
|
|
70
|
+
gen_list = {() n, nil list} gen_list_;
|
|
71
|
+
gen_list_ = <
|
|
72
|
+
{.n neg? if, .list then} .then,
|
|
73
|
+
{.n dec n, {.n car, .list cdr} cons list} gen_list_
|
|
74
|
+
>;
|
|
75
|
+
|
|
76
|
+
-- Identity filter on {x, y} when x is greater than y: ?{X x, X y}=Y -> ?Y
|
|
77
|
+
gt? =
|
|
78
|
+
<
|
|
79
|
+
{.x/- if1, .y/+ if2, () then} .then,
|
|
80
|
+
{{.x/- y, .y/- x} GT if, () then} .then,
|
|
81
|
+
{{.x/+ x, .y/+ y} GT if, () then} .then
|
|
82
|
+
>
|
|
83
|
+
;
|
|
84
|
+
|
|
85
|
+
-- Split list into two halves by alternating elements: xs -> {first, second}
|
|
86
|
+
split = {() xs, nil first, nil second} _split;
|
|
87
|
+
_split = <
|
|
88
|
+
{.xs /nil if, {.first first, .second second} then} .then,
|
|
89
|
+
{.xs cdr /nil if, {{.xs car car, .first cdr} cons first, .second second} then} .then,
|
|
90
|
+
{.xs cdr cdr xs, {.xs car car, .first cdr} cons first, {.xs cdr car car, .second cdr} cons second} _split
|
|
91
|
+
>;
|
|
92
|
+
|
|
93
|
+
-- Merge two sorted lists: {xs, ys} -> list
|
|
94
|
+
merge = <
|
|
95
|
+
{.xs /nil if, .ys then} .then,
|
|
96
|
+
{.ys /nil if, .xs then} .then,
|
|
97
|
+
{
|
|
98
|
+
{.xs car x, .ys car y} gt? if,
|
|
99
|
+
{.ys car car, {.xs xs, .ys cdr ys} merge cdr} cons then
|
|
100
|
+
} .then,
|
|
101
|
+
{.xs car car, {.xs cdr xs, .ys ys} merge cdr} cons
|
|
102
|
+
>;
|
|
103
|
+
|
|
104
|
+
-- Sort a list in ascending order (merge sort): xs -> list
|
|
105
|
+
sort = list? <
|
|
106
|
+
/nil nil,
|
|
107
|
+
/cons <
|
|
108
|
+
{.cdr /nil if, .car singleton then} .then,
|
|
109
|
+
|cons split {.first sort xs, .second sort ys} merge
|
|
110
|
+
>
|
|
111
|
+
> list?;
|
|
112
|
+
|
|
113
|
+
|