@fraczak/k 2.1.6 → 3.0.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.
@@ -0,0 +1,45 @@
1
+ import { unify_with_code } from './filters.mjs';
2
+ import k from './index.mjs';
3
+ // { compile, run, parse, annotate };
4
+
5
+ const annotated = k.annotate(`
6
+ $nat = < {} _, nat s >;
7
+ $pair = { nat x, nat y };
8
+ $list = < {} empty, { nat x, list xs } list>;
9
+ z = {{} _} $nat;
10
+ s = { $nat s} $nat;
11
+ f1 = ? { n x, ...};
12
+ f2 = ? { <...> y, ...};
13
+ f3 = ? < x empty, { $MWqNxWxHMy xs, ...} list >;
14
+ {}
15
+ `);
16
+
17
+
18
+
19
+ // console.log(JSON.stringify(annotated, null, 2));
20
+
21
+
22
+
23
+ const test1 = unify_with_code(
24
+ annotated.codes,
25
+ annotated.representatives["pair"],
26
+ annotated.rels['f1'][0].filter,
27
+ {}
28
+ );
29
+ console.log(JSON.stringify(test1, null, 2));
30
+
31
+ const test2 = unify_with_code(
32
+ annotated.codes,
33
+ annotated.representatives["pair"],
34
+ annotated.rels['f2'][0].filter,
35
+ {}
36
+ );
37
+ console.log(JSON.stringify(test2, null, 2));
38
+
39
+ const test3 = unify_with_code(
40
+ annotated.codes,
41
+ annotated.representatives["list"],
42
+ annotated.rels['f3'][0].filter,
43
+ {}
44
+ );
45
+ console.log(JSON.stringify(test3, null, 2));
@@ -0,0 +1,38 @@
1
+ import k from './index.mjs';
2
+ import { encodeCodeToString } from './codes.mjs';
3
+ import hash from './hash.mjs';
4
+ [
5
+ `
6
+ $nat = < {} zero, nat succ>;
7
+ $pair = {nat x, nat y};
8
+ $b = {int"x", bool y};
9
+ $vector = [int];
10
+ $tree = <{nat value, tree left, tree right} binary, {nat value} leaf, {nat value, tree tree} unary, [tree] list_of_trees>;
11
+
12
+ succ = { $nat succ} $nat;
13
+ plus = $pair <
14
+ {.x.zero stop, .y result} .result,
15
+ {.x.succ x, .y succ y } plus
16
+ > $nat;
17
+ {{} zero} succ succ {() x, () y} plus
18
+ `
19
+ ].map(function (script) {
20
+ console.log(`k_expression = '${script}';`);
21
+ const annotated = k.annotate(script);
22
+ for (const code in annotated.codes) {
23
+ console.log(`CODE: ${code}`);
24
+ const s = encodeCodeToString(code,annotated.codes);
25
+ console.log(` - DEFS: ${s}`);;
26
+ const annotated2 = k.annotate(s+" {}");;
27
+ const s2 = encodeCodeToString(annotated2.representatives["C0"],annotated2.codes);
28
+ console.log(` - reparsed FINGERPRINT: ${hash(s2)}`);
29
+ if ((s === s2) && (hash(s) === hash(s2))) {
30
+ console.log('--- OK');
31
+ } else {
32
+ console.log('--- ERROR');
33
+ }
34
+
35
+ console.log('-------------------');
36
+ }
37
+ });
38
+
package/test.mjs CHANGED
@@ -34,7 +34,7 @@ import k from "./index.mjs";
34
34
  });
35
35
 
36
36
  let k_expression =
37
- '{.name nom, <[.age, 18] GT .0, [.age, 12] GT "ado", "enfant"> age}';
37
+ '{.name nom, <[.age, 18] GT "old", [.age, 12] GT "ado", "enfant"> age}';
38
38
 
39
39
  let k_fn = k.compile(k_expression);
40
40
 
@@ -61,48 +61,6 @@ console.log("");
61
61
  return console.log("");
62
62
  });
63
63
 
64
- k_expression = "$t = < i: int, t: [ t ] > ; <$t, $int>";
65
-
66
- k_fn = k.compile(k_expression);
67
-
68
- console.log(`var k_fn = k.compile('${k_expression}');`);
69
-
70
- console.log("");
71
-
72
- [
73
- 1,
74
- {
75
- i: 1,
76
- },
77
- [
78
- {
79
- i: 2,
80
- },
81
- {
82
- i: 3,
83
- },
84
- {
85
- t: [],
86
- },
87
- ],
88
- {
89
- t: [
90
- {
91
- i: 2,
92
- },
93
- {
94
- i: 3,
95
- },
96
- {
97
- t: [],
98
- },
99
- ],
100
- },
101
- ].map(function (data) {
102
- console.log(`k_fn(${JSON.stringify(data)});`);
103
- console.log(`// RETURNS: ${JSON.stringify(k_fn(data))}`);
104
- return console.log("");
105
- });
106
64
 
107
65
  k_expression = "$ < < [ int ] ints, [ bool ] bools > list, string None>";
108
66