@fraczak/k 4.0.2 → 4.0.3

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 CHANGED
@@ -4,11 +4,51 @@
4
4
 
5
5
  From javascript:
6
6
 
7
- import k from "@fraczak/k";
7
+ ```js
8
+ import k from "@fraczak/k"
8
9
 
9
- const fn = k.compile("<.name,.nom,'?'>");
10
- console.log([{name:"x"},{nom:"y"},{}].map(fn));
11
- // returns: [ "x", "y", "?" ]
10
+ const fn = k.compile(` -- complete "pure" k-program
11
+ $ nat = < {} o, nat i >; -- unary natural number encoding
12
+ succ = {() i} $nat; -- increment relation definition
13
+ succ succ succ -- +3 (in the above encoding)
14
+ `);
15
+ const three = {i:{i:{i:{o:{}}}}};
16
+ const six = fn(three);
17
+ console.log(JSON.stringify( six ));
18
+ // {"i":{"i":{"i":{"i":{"i":{"i":{"o":{}}}}}}}}
19
+
20
+ ```
21
+
22
+ Working with REPL:
23
+
24
+ ```
25
+ $ k-repl
26
+ Very! experimental repl shell for 'k-language'...
27
+ --c print aliased codes
28
+ --C code print 'code' definition
29
+ --r print relations
30
+ --R rel print 'rel' definition with type patterns
31
+ --p (--pp) pretty-print last value
32
+ --s (--g) reg store (get) the current value in (from) register 'reg'
33
+ --regs print register names
34
+ --l file.k load 'file.k'
35
+ > -- DEMO: comments start with '--', like this line \
36
+ -- Code (type) definitions: ` $ code-name = code-expression ;` \
37
+ $ unit = { } ; -- empty product code \
38
+ $ bits = <unit _, bits 0, bits 1>; -- union, 3 variants tagged: _, 0, 1 \
39
+ -- Now, we will define relations: ` name = expression ; ` \
40
+ empty = {{} _} ; -- alternative JSON-like syntax {_: {}} allowed \
41
+ _001 = {0: {0: {1: empty}}}; -- in JSON-like syntax \
42
+ reverse_ = < -- priority merge \
43
+ {.in.0 in, {.out 0} out} reverse_, \
44
+ {.in.1 in, {.out 1} out} reverse_, \
45
+ .out >; \
46
+ reverse = {() in, empty out} reverse_ ; \
47
+ _001 reverse -- run the expression (composition of 2 relations)
48
+ --> {"1":{"0":{"0":{"_":{}}}}}
49
+ > toStr = < .0 ["0",toStr] CONCAT, .1 ["1",toStr] CONCAT, "" >; toStr
50
+ --> "100"
51
+ ```
12
52
 
13
53
  ---
14
54