@dallaylaen/ski-interpreter 2.3.0 → 2.3.2
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 +17 -0
- package/README.md +1 -1
- package/bin/ski.js +74 -0
- package/lib/ski-interpreter.cjs.js +5 -1
- package/lib/ski-interpreter.cjs.js.map +2 -2
- package/lib/ski-interpreter.esm.js +5 -1
- package/lib/ski-interpreter.esm.js.map +2 -2
- package/lib/ski-interpreter.min.js +3 -3
- package/lib/ski-interpreter.min.js.map +3 -3
- package/lib/ski-quest.min.js +3 -3
- package/lib/ski-quest.min.js.map +3 -3
- package/package.json +1 -1
- package/types/src/extras.d.ts +14 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.3.2] - 2026-03-01
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `SKI.extras.foldr(expr: Expr, fun: (expr: Expr, args: T[]) => T): T` (experimental) -
|
|
13
|
+
apply function `fun` to every term in root position in a subexpression,
|
|
14
|
+
followed by the result of folding its arguments.
|
|
15
|
+
|
|
16
|
+
## [2.3.1] - 2026-03-01
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
- Links in documentation.
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
- `ski.js extract <expression> <term> ...` - rewrite the given expression to an equivalent using provided terms where possible.
|
|
23
|
+
- `ski.js search <expression> <term> ...` - brute-force search for an expression equivalent to the given one using the provided terms.
|
|
24
|
+
|
|
8
25
|
## [2.3.0] - 2026-02-28
|
|
9
26
|
|
|
10
27
|
### BREAKING CHANGES
|
package/README.md
CHANGED
|
@@ -270,7 +270,7 @@ q.check('K'); // fail
|
|
|
270
270
|
q.check('K(K(y x))') // nope! the variable scopes won't match
|
|
271
271
|
```
|
|
272
272
|
|
|
273
|
-
See also [the quest guide](
|
|
273
|
+
See also [the quest guide](quest-intro.md) for more details on building your own quests or even interactive quest pages.
|
|
274
274
|
|
|
275
275
|
# Package contents
|
|
276
276
|
|
package/bin/ski.js
CHANGED
|
@@ -40,6 +40,22 @@ program
|
|
|
40
40
|
evaluateFile(filepath, options.verbose);
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
+
// Search subcommand
|
|
44
|
+
program
|
|
45
|
+
.command('search <target> <terms...>')
|
|
46
|
+
.description('Search for an expression equivalent to target using known terms')
|
|
47
|
+
.action((target, terms) => {
|
|
48
|
+
searchExpression(target, terms);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Extract subcommand
|
|
52
|
+
program
|
|
53
|
+
.command('extract <target> <terms...>')
|
|
54
|
+
.description('Rewrite target expression using known terms where possible')
|
|
55
|
+
.action((target, terms) => {
|
|
56
|
+
extractExpression(target, terms);
|
|
57
|
+
});
|
|
58
|
+
|
|
43
59
|
// Quest-check subcommand
|
|
44
60
|
program
|
|
45
61
|
.command('quest-check <files...>')
|
|
@@ -203,6 +219,64 @@ async function questCheck (files, solutionFile) {
|
|
|
203
219
|
}
|
|
204
220
|
}
|
|
205
221
|
|
|
222
|
+
function searchExpression (targetStr, termStrs) {
|
|
223
|
+
const ski = new SKI();
|
|
224
|
+
const jar = {};
|
|
225
|
+
const target = ski.parse(targetStr, { vars: jar });
|
|
226
|
+
const seed = termStrs.map(s => ski.parse(s, { vars: jar }));
|
|
227
|
+
|
|
228
|
+
const { expr } = target.infer();
|
|
229
|
+
if (!expr) {
|
|
230
|
+
console.error('target expression is not normalizable: ' + target);
|
|
231
|
+
process.exit(1);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const res = SKI.extras.search(seed, { tries: 10_000_000, depth: 100 }, (e, p) => {
|
|
235
|
+
if (!p.expr)
|
|
236
|
+
return -1;
|
|
237
|
+
if (p.expr.equals(expr))
|
|
238
|
+
return 1;
|
|
239
|
+
return 0;
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
if (res.expr) {
|
|
243
|
+
console.log(`Found ${res.expr} after ${res.total} tries.`);
|
|
244
|
+
process.exit(0);
|
|
245
|
+
} else {
|
|
246
|
+
console.error(`No equivalent expression found for ${target} after ${res.total} tries.`);
|
|
247
|
+
process.exit(1);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function extractExpression (targetStr, termStrs) {
|
|
252
|
+
const ski = new SKI();
|
|
253
|
+
const expr = ski.parse(targetStr);
|
|
254
|
+
const pairs = termStrs
|
|
255
|
+
.map(s => ski.parse(s))
|
|
256
|
+
.map(e => [e.infer().expr, e]);
|
|
257
|
+
|
|
258
|
+
const uncanonical = pairs.filter(pair => !pair[0]);
|
|
259
|
+
if (uncanonical.length) {
|
|
260
|
+
console.error('Some expressions could not be canonized: '
|
|
261
|
+
+ uncanonical.map(p => p[1].toString()).join(', '));
|
|
262
|
+
process.exit(1);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const replaced = expr.traverse(e => {
|
|
266
|
+
const canon = e.infer().expr;
|
|
267
|
+
for (const [lambda, term] of pairs) {
|
|
268
|
+
if (canon.equals(lambda))
|
|
269
|
+
return term;
|
|
270
|
+
}
|
|
271
|
+
return null;
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
if (replaced)
|
|
275
|
+
console.log(replaced.toString());
|
|
276
|
+
else
|
|
277
|
+
console.log('// unchanged');
|
|
278
|
+
}
|
|
279
|
+
|
|
206
280
|
function handleCommand (input, ski) {
|
|
207
281
|
const parts = input.trim().split(/\s+/);
|
|
208
282
|
const cmd = parts[0];
|
|
@@ -2220,7 +2220,11 @@ var require_extras = __commonJS({
|
|
|
2220
2220
|
return s.format({ inventory: res.env });
|
|
2221
2221
|
}).join("; ");
|
|
2222
2222
|
}
|
|
2223
|
-
|
|
2223
|
+
function foldr(expr, fun) {
|
|
2224
|
+
const [head, ...tail] = expr.unroll();
|
|
2225
|
+
return fun(head, tail.map((e) => foldr(e, fun)));
|
|
2226
|
+
}
|
|
2227
|
+
module2.exports = { search, deepFormat, declare, foldr };
|
|
2224
2228
|
}
|
|
2225
2229
|
});
|
|
2226
2230
|
|