@fraczak/k 4.0.2 → 4.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fraczak/k",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
4
4
  "description": "k-language for JSON-like data transformation",
5
5
  "main": "index.mjs",
6
6
  "scripts": {
package/repl.mjs CHANGED
@@ -15,11 +15,11 @@ console.log("Very! experimental repl shell for 'k-language'...");
15
15
  const help = function () {
16
16
  // console.log(" --debug loads codes and relations as value");
17
17
  console.log(" --c print aliased codes");
18
- console.log(" --C code print code definition");
19
- console.log(" --r print rels");
20
- console.log(" --R rel print out the type pattern of 'rel'");
18
+ console.log(" --C code print 'code' definition");
19
+ console.log(" --r print relations");
20
+ console.log(" --R rel print 'rel' definition with type patterns");
21
21
  console.log(" --p (--pp) pretty-print last value");
22
- console.log(" --s (--g) reg store (get) the last value in register 'reg'");
22
+ console.log(" --s (--g) reg store (get) the current value in (from) register 'reg'");
23
23
  console.log(" --regs print register names");
24
24
  console.log(" --l file.k load 'file.k'");
25
25
  };
@@ -54,7 +54,7 @@ const printVal = function (v = val) {
54
54
  if (v === undefined)
55
55
  console.log("...",v);
56
56
  else
57
- console.log(`=> ${JSON.stringify(v)}`);
57
+ console.log(`--> ${JSON.stringify(v)}`);
58
58
  rl.setPrompt('> ');
59
59
  }
60
60
  const registers = {};
@@ -100,10 +100,9 @@ function evaluate(line) {
100
100
  return result;
101
101
  }
102
102
  return (function (prettyRel) {
103
- let ref1, relName;
104
- ref1 = defs.rels;
105
- for (relName in ref1) {
106
- result[relName] = prettyRel(ref1[relName].def);
103
+ for (const relName in defs.rels) {
104
+ if (relName != "__main__")
105
+ result[relName] = prettyRel(defs.rels[relName].def);
107
106
  }
108
107
  return result;
109
108
  })(
@@ -172,7 +171,8 @@ function evaluate(line) {
172
171
  // for (const filter of filters) {
173
172
  const pcodef= prettyCode.bind(null, run.defs.representatives);
174
173
  const filtersStr = filters.map( x => prettyRel(pcodef, {op: "filter", filter: x}));
175
- console.log(` ${relName} : ${filtersStr[0]} --> ${filtersStr[1]}`);
174
+ console.log(` ${relName} : ${filtersStr[0]} --> ${filtersStr[1]}`);
175
+ console.log(` ${relName} = ${prettyRel(pcodef,rel.def)};`);
176
176
  // }
177
177
  // ------ k code
178
178
  } else if (!line.match(/^[ \n\t]*(?:#.*)?$/)) {
@@ -180,12 +180,11 @@ function evaluate(line) {
180
180
  val = k.run(`+++\n${line}\n()`, val);
181
181
  printVal();
182
182
  } catch (error) {
183
- e = error;
184
- console.error("ERROR:");
185
- console.error(e);
183
+ console.error(error.message);
186
184
  }
187
185
  }
188
186
  } catch (e) {
189
187
  console.error(e.message);
188
+ console.error(e);
190
189
  }
191
190
  }
package/run.mjs CHANGED
@@ -248,7 +248,9 @@ function run(exp, value) {
248
248
  }
249
249
  case "caret": {
250
250
  const result = run(exp.caret, value);
251
- assert(isOpen(result), "CARET (^): Only an 'open' vector can be closed.");
251
+ // assert(isOpen(result), "CARET (^): Only an 'open' vector can be closed.");
252
+ if (! isOpen(result))
253
+ throw new Error(`Type Error (line: ${exp.end?.line}:${exp.end?.column}): CARET (^): Only 'unboxed' values can be 'boxed'.`)
252
254
  return [...result];
253
255
  }
254
256
  case "filter": {
package/TYPES.md DELETED
@@ -1,32 +0,0 @@
1
- # What if we concider partial functions as filter-to-filter mappings?
2
-
3
- ## Examples
4
-
5
- ```k
6
- .x :: ( X x, ... ) -> X
7
- { f1 x1, f2 x2, ..., fn xn } :: X -> { f1(X) x1, f2(X) x2, ..., fn(X) xn }
8
- { f x } :: X -> < f(X) x, ... >
9
- < f1, f2, ..., fn > :: X -> f1(X) // f1 == f2 == ... == fn
10
- [ f1, f2, ..., fn ] :: X -> [f1(X)] // f1 == f2 == ... == fn
11
- $code ::
12
- ```
13
-
14
- Let's consider the following example:
15
-
16
- ```k
17
- $nat = < {} _, nat s >;
18
- z = {{} _}; -- X -> <{} _, ...>
19
- s = {() s}; -- X -> <X s, ...>
20
-
21
- add =
22
- <
23
- {.x ._ if, .y then} .then,
24
- {.x .s x, .y s y } add
25
- >
26
- ;
27
-
28
- double = {() x, () y} add;
29
-
30
- z s s $nat double;
31
- ```
32
-