@dallaylaen/ski-interpreter 2.3.2 → 2.4.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 +26 -0
- package/README.md +9 -2
- package/bin/ski.js +10 -7
- package/lib/ski-interpreter.cjs.js +2082 -2187
- package/lib/ski-interpreter.cjs.js.map +4 -4
- package/lib/ski-interpreter.esm.js +2065 -2198
- package/lib/ski-interpreter.esm.js.map +4 -4
- package/lib/ski-interpreter.min.js +3 -3
- package/lib/ski-interpreter.min.js.map +4 -4
- package/lib/ski-quest.min.js +3 -3
- package/lib/ski-quest.min.js.map +4 -4
- package/{types/src → lib/types}/expr.d.ts +238 -248
- package/{types/src → lib/types}/extras.d.ts +24 -23
- package/lib/types/index.d.ts +68 -0
- package/{types/src → lib/types}/internal.d.ts +27 -23
- package/{types/src → lib/types}/parser.d.ts +40 -83
- package/lib/types/quest.d.ts +232 -0
- package/lib/types/toposort.d.ts +30 -0
- package/package.json +13 -12
- package/types/index.d.ts +0 -3
- package/types/src/quest.d.ts +0 -257
|
@@ -1,39 +1,79 @@
|
|
|
1
|
-
|
|
2
|
-
export type Partial = Expr | ((arg0: Expr) => Partial);
|
|
1
|
+
import { TraverseValue, Dict } from './internal';
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
5
|
-
* arity?: number, // the number of arguments that is sufficient to reach the normal form
|
|
6
|
-
* // absent unless normal.
|
|
7
|
-
* discard?: boolean, // whether the term (or subterms, unless proper) can discard arguments.
|
|
8
|
-
* duplicate?: boolean, // whether the term (or subterms, unless proper) can duplicate arguments.
|
|
9
|
-
* skip?: Set<number>, // indices of arguments that are discarded. nonempty inplies discard.
|
|
10
|
-
* dup?: Set<number>, // indices of arguments that are duplicated. nonempty implies duplicate.
|
|
11
|
-
* expr?: Expr, // canonical form containing lambdas, applications, and variables, if any
|
|
12
|
-
* steps?: number, // number of steps taken to obtain the aforementioned information, if applicable
|
|
13
|
-
* }} TermInfo
|
|
3
|
+
* @desc Control primitives for fold() and traverse() methods.
|
|
14
4
|
*/
|
|
15
|
-
export
|
|
16
|
-
|
|
5
|
+
export declare const control: {
|
|
6
|
+
descend: <T>(value: T) => import("./internal").TraverseControl<T>;
|
|
7
|
+
prune: <T>(value: T) => import("./internal").TraverseControl<T>;
|
|
8
|
+
redo: <T>(value: T) => import("./internal").TraverseControl<T>;
|
|
9
|
+
stop: <T>(value: T) => import("./internal").TraverseControl<T>;
|
|
17
10
|
};
|
|
18
11
|
/**
|
|
19
|
-
* @
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @typedef {{
|
|
23
|
-
* normal: boolean, // whether the term becomes irreducible after receiving a number of arguments.
|
|
24
|
-
* // if false, other properties may be missing.
|
|
25
|
-
* proper: boolean, // whether the irreducible form is only contains its arguments. implies normal.
|
|
26
|
-
* arity?: number, // the number of arguments that is sufficient to reach the normal form
|
|
27
|
-
* // absent unless normal.
|
|
28
|
-
* discard?: boolean, // whether the term (or subterms, unless proper) can discard arguments.
|
|
29
|
-
* duplicate?: boolean, // whether the term (or subterms, unless proper) can duplicate arguments.
|
|
30
|
-
* skip?: Set<number>, // indices of arguments that are discarded. nonempty inplies discard.
|
|
31
|
-
* dup?: Set<number>, // indices of arguments that are duplicated. nonempty implies duplicate.
|
|
32
|
-
* expr?: Expr, // canonical form containing lambdas, applications, and variables, if any
|
|
33
|
-
* steps?: number, // number of steps taken to obtain the aforementioned information, if applicable
|
|
34
|
-
* }} TermInfo
|
|
12
|
+
* @desc List of predefined native combinators.
|
|
13
|
+
* This is required for toSKI() to work, otherwise could as well have been in parser.js.
|
|
35
14
|
*/
|
|
36
|
-
export
|
|
15
|
+
export declare const native: Dict<Native>;
|
|
16
|
+
export type TermInfo = {
|
|
17
|
+
normal: boolean;
|
|
18
|
+
proper: boolean;
|
|
19
|
+
arity?: number;
|
|
20
|
+
discard?: boolean;
|
|
21
|
+
duplicate?: boolean;
|
|
22
|
+
skip?: Set<number>;
|
|
23
|
+
dup?: Set<number>;
|
|
24
|
+
expr?: Expr;
|
|
25
|
+
steps?: number;
|
|
26
|
+
};
|
|
27
|
+
export type Invocation = Expr | ((arg: Expr) => Invocation);
|
|
28
|
+
export type Step = {
|
|
29
|
+
expr: Expr;
|
|
30
|
+
steps: number;
|
|
31
|
+
changed: boolean;
|
|
32
|
+
};
|
|
33
|
+
export type Run = {
|
|
34
|
+
expr: Expr;
|
|
35
|
+
steps: number;
|
|
36
|
+
final: boolean;
|
|
37
|
+
};
|
|
38
|
+
export type RunOptions = {
|
|
39
|
+
max?: number;
|
|
40
|
+
steps?: number;
|
|
41
|
+
throw?: boolean;
|
|
42
|
+
};
|
|
43
|
+
export type FormatOptions = {
|
|
44
|
+
terse?: boolean;
|
|
45
|
+
html?: boolean;
|
|
46
|
+
brackets?: [string, string];
|
|
47
|
+
space?: string;
|
|
48
|
+
var?: [string, string];
|
|
49
|
+
lambda?: [string, string, string];
|
|
50
|
+
around?: [string, string];
|
|
51
|
+
redex?: [string, string];
|
|
52
|
+
inventory?: Dict<Expr>;
|
|
53
|
+
};
|
|
54
|
+
type RefinedFormatOptions = {
|
|
55
|
+
terse?: boolean;
|
|
56
|
+
html?: boolean;
|
|
57
|
+
brackets: [string, string];
|
|
58
|
+
space: string;
|
|
59
|
+
var: [string, string];
|
|
60
|
+
lambda: [string, string, string];
|
|
61
|
+
around: [string, string];
|
|
62
|
+
redex: [string, string];
|
|
63
|
+
inventory?: Dict<Expr>;
|
|
64
|
+
};
|
|
65
|
+
type TraverseOptions = {
|
|
66
|
+
order?: 'LO' | 'LI' | 'leftmost-outermost' | 'leftmost-innermost';
|
|
67
|
+
};
|
|
68
|
+
type TraverseCallback = (e: Expr) => TraverseValue<Expr>;
|
|
69
|
+
export declare class Expr {
|
|
70
|
+
static control: {
|
|
71
|
+
descend: <T>(value: T) => import("./internal").TraverseControl<T>;
|
|
72
|
+
prune: <T>(value: T) => import("./internal").TraverseControl<T>;
|
|
73
|
+
redo: <T>(value: T) => import("./internal").TraverseControl<T>;
|
|
74
|
+
stop: <T>(value: T) => import("./internal").TraverseControl<T>;
|
|
75
|
+
};
|
|
76
|
+
static native: Dict<Native>;
|
|
37
77
|
/**
|
|
38
78
|
* @descr A combinatory logic expression.
|
|
39
79
|
*
|
|
@@ -53,6 +93,15 @@ export class Expr {
|
|
|
53
93
|
* Typically only applicable to descendants of Named.
|
|
54
94
|
* @property {TermInfo} [props] - properties inferred from the term's behavior
|
|
55
95
|
*/
|
|
96
|
+
context?: {
|
|
97
|
+
scope?: object;
|
|
98
|
+
env?: Dict<Expr>;
|
|
99
|
+
src?: string;
|
|
100
|
+
parser: object;
|
|
101
|
+
};
|
|
102
|
+
arity?: number;
|
|
103
|
+
note?: string;
|
|
104
|
+
props?: TermInfo;
|
|
56
105
|
/**
|
|
57
106
|
*
|
|
58
107
|
* @desc Define properties of the term based on user supplied options and/or inference results.
|
|
@@ -67,28 +116,26 @@ export class Expr {
|
|
|
67
116
|
* @param {number} [options.maxArgs] - maximum number of arguments for inference, if canonize is true
|
|
68
117
|
* @return {this}
|
|
69
118
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
119
|
+
_setup(options?: {
|
|
120
|
+
note?: string;
|
|
121
|
+
arity?: number;
|
|
122
|
+
fancy?: string;
|
|
123
|
+
canonize?: boolean;
|
|
124
|
+
max?: number;
|
|
125
|
+
maxArgs?: number;
|
|
126
|
+
}): this;
|
|
75
127
|
/**
|
|
76
128
|
* @desc apply self to zero or more terms and return the resulting term,
|
|
77
129
|
* without performing any calculations whatsoever
|
|
78
130
|
* @param {Expr} args
|
|
79
131
|
* @return {Expr}
|
|
80
132
|
*/
|
|
81
|
-
apply(...args: Expr): Expr;
|
|
133
|
+
apply(...args: Expr[]): Expr;
|
|
82
134
|
/**
|
|
83
135
|
* @desc Replace all aliases in the expression with their definitions, recursively.
|
|
84
136
|
* @return {Expr}
|
|
85
137
|
*/
|
|
86
138
|
expand(): Expr;
|
|
87
|
-
/**
|
|
88
|
-
* @desc Returns true if the expression contains only free variables and applications, false otherwise.
|
|
89
|
-
* @returns {boolean}
|
|
90
|
-
*/
|
|
91
|
-
freeOnly(): boolean;
|
|
92
139
|
/**
|
|
93
140
|
* @desc Traverse the expression tree, applying change() to each node.
|
|
94
141
|
* If change() returns an Expr, the node is replaced with that value.
|
|
@@ -115,23 +162,21 @@ export class Expr {
|
|
|
115
162
|
* @param {(e:Expr) => TraverseValue<Expr>} change
|
|
116
163
|
* @returns {Expr|null}
|
|
117
164
|
*/
|
|
118
|
-
traverse(options?:
|
|
119
|
-
order?: "LO" | "LI" | "leftmost-outermost" | "leftmost-innermost";
|
|
120
|
-
}, change: (e: Expr) => TraverseValue<Expr>): Expr | null;
|
|
165
|
+
traverse(options: TraverseOptions | TraverseCallback, change?: TraverseCallback): Expr | null;
|
|
121
166
|
/**
|
|
122
167
|
* @private
|
|
123
168
|
* @param {Object} options
|
|
124
169
|
* @param {(e:Expr) => TraverseValue<Expr>} change
|
|
125
170
|
* @returns {TraverseValue<Expr>}
|
|
126
171
|
*/
|
|
127
|
-
|
|
172
|
+
_traverse_redo(options: TraverseOptions, change: TraverseCallback): TraverseValue<Expr>;
|
|
128
173
|
/**
|
|
129
174
|
* @private
|
|
130
175
|
* @param {Object} options
|
|
131
176
|
* @param {(e:Expr) => TraverseValue<Expr>} change
|
|
132
177
|
* @returns {TraverseValue<Expr>}
|
|
133
178
|
*/
|
|
134
|
-
|
|
179
|
+
_traverse_descend(options: TraverseOptions, change: TraverseCallback): TraverseValue<Expr>;
|
|
135
180
|
/**
|
|
136
181
|
* @desc Returns true if predicate() is true for any subterm of the expression, false otherwise.
|
|
137
182
|
*
|
|
@@ -158,20 +203,33 @@ export class Expr {
|
|
|
158
203
|
* @param {(acc: T, expr: Expr) => TraverseValue<T>} combine
|
|
159
204
|
* @returns {T}
|
|
160
205
|
*/
|
|
161
|
-
fold<
|
|
206
|
+
fold<T>(initial: T, combine: (acc: T, expr: Expr) => TraverseValue<T>): T;
|
|
207
|
+
_fold<T>(initial: T, combine: (acc: T, expr: Expr) => TraverseValue<T>): TraverseValue<T>;
|
|
162
208
|
/**
|
|
209
|
+
* @experimental
|
|
210
|
+
* @desc Fold an application tree bottom to top.
|
|
211
|
+
* For each subtree, the function is given the term in the root position and
|
|
212
|
+
* a list of the results of folding its arguments.
|
|
213
|
+
*
|
|
214
|
+
* E.g. fold('x y (z t)', f) results in f(x, [f(y, []), f(z, [f(t, [])])])
|
|
215
|
+
*
|
|
216
|
+
* @example expr.foldBottomUp((head, tail) => {
|
|
217
|
+
* if (head.arity && head.arity <= tail.length) {
|
|
218
|
+
* return '(<span class="redex">'
|
|
219
|
+
* + head + ' '
|
|
220
|
+
* + tail.slice(0, head.arity).join(' ')
|
|
221
|
+
* + '</span>'
|
|
222
|
+
* + tail.slice(head.arity).join(' ')
|
|
223
|
+
* + ')';
|
|
224
|
+
* } else {
|
|
225
|
+
* return '(' + head + ' ' + tail.join(' ') + ')';
|
|
226
|
+
* }
|
|
227
|
+
* });
|
|
163
228
|
* @template T
|
|
164
|
-
* @param {T}
|
|
165
|
-
* @
|
|
166
|
-
* @returns {TraverseValue<T>}
|
|
167
|
-
* @private
|
|
229
|
+
* @param {(head: Expr, tail: T[]) => T} fun
|
|
230
|
+
* @return {T}
|
|
168
231
|
*/
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* @desc rough estimate of the term's complexity
|
|
172
|
-
* @return {number}
|
|
173
|
-
*/
|
|
174
|
-
weight(): number;
|
|
232
|
+
foldBottomUp<T>(fun: (head: Expr, tail: T[]) => T): T;
|
|
175
233
|
/**
|
|
176
234
|
* @desc Try to empirically find an equivalent lambda term for the expression,
|
|
177
235
|
* returning also the term's arity and some other properties.
|
|
@@ -198,7 +256,11 @@ export class Expr {
|
|
|
198
256
|
* @returns {TermInfo}
|
|
199
257
|
* @private
|
|
200
258
|
*/
|
|
201
|
-
|
|
259
|
+
_infer(options: {
|
|
260
|
+
max: number;
|
|
261
|
+
maxArgs: number;
|
|
262
|
+
skipNames: Dict<boolean>;
|
|
263
|
+
}, nargs: number): TermInfo;
|
|
202
264
|
/**
|
|
203
265
|
* @desc Expand an expression into a list of terms
|
|
204
266
|
* that give the initial expression when applied from left to right:
|
|
@@ -213,8 +275,7 @@ export class Expr {
|
|
|
213
275
|
unroll(): Expr[];
|
|
214
276
|
/**
|
|
215
277
|
* @desc Returns a series of lambda terms equivalent to the given expression,
|
|
216
|
-
* up to the provided computation steps limit
|
|
217
|
-
* in decreasing weight order.
|
|
278
|
+
* up to the provided computation steps limit.
|
|
218
279
|
*
|
|
219
280
|
* Unlike infer(), this method will always return something,
|
|
220
281
|
* even if the expression has no normal form.
|
|
@@ -229,21 +290,15 @@ export class Expr {
|
|
|
229
290
|
* html?: boolean,
|
|
230
291
|
* latin?: number,
|
|
231
292
|
* }} options
|
|
232
|
-
* @param {number} [maxWeight] - maximum allowed weight of terms in the sequence
|
|
233
293
|
* @return {IterableIterator<{expr: Expr, steps?: number, comment?: string}>}
|
|
234
294
|
*/
|
|
235
295
|
toLambda(options?: {
|
|
236
296
|
max?: number;
|
|
237
297
|
maxArgs?: number;
|
|
238
|
-
|
|
239
|
-
steps?: number;
|
|
240
|
-
html?: boolean;
|
|
241
|
-
latin?: number;
|
|
242
|
-
}): IterableIterator<{
|
|
298
|
+
}): Generator<{
|
|
243
299
|
expr: Expr;
|
|
244
|
-
steps
|
|
245
|
-
|
|
246
|
-
}>;
|
|
300
|
+
steps: number;
|
|
301
|
+
}, void, unknown>;
|
|
247
302
|
/**
|
|
248
303
|
* @desc Rewrite the expression into S, K, and I combinators step by step.
|
|
249
304
|
* Returns an iterator yielding the intermediate expressions,
|
|
@@ -254,13 +309,11 @@ export class Expr {
|
|
|
254
309
|
* @param {{max?: number}} [options]
|
|
255
310
|
* @return {IterableIterator<{final: boolean, expr: Expr, steps: number}>}
|
|
256
311
|
*/
|
|
257
|
-
toSKI(
|
|
258
|
-
max?: number;
|
|
259
|
-
}): IterableIterator<{
|
|
260
|
-
final: boolean;
|
|
312
|
+
toSKI(_options?: {}): Generator<{
|
|
261
313
|
expr: Expr;
|
|
262
314
|
steps: number;
|
|
263
|
-
|
|
315
|
+
final: boolean;
|
|
316
|
+
}, void, unknown>;
|
|
264
317
|
/**
|
|
265
318
|
* Replace all instances of plug in the expression with value and return the resulting expression,
|
|
266
319
|
* or null if no changes could be made.
|
|
@@ -292,16 +345,12 @@ export class Expr {
|
|
|
292
345
|
* @param {Expr} arg
|
|
293
346
|
* @returns {Partial | null}
|
|
294
347
|
*/
|
|
295
|
-
invoke(arg: Expr):
|
|
348
|
+
invoke(arg: Expr): Invocation | null;
|
|
296
349
|
/**
|
|
297
350
|
* @desc iterate one step of a calculation.
|
|
298
351
|
* @return {{expr: Expr, steps: number, changed: boolean}}
|
|
299
352
|
*/
|
|
300
|
-
step():
|
|
301
|
-
expr: Expr;
|
|
302
|
-
steps: number;
|
|
303
|
-
changed: boolean;
|
|
304
|
-
};
|
|
353
|
+
step(): Step;
|
|
305
354
|
/**
|
|
306
355
|
* @desc Run uninterrupted sequence of step() applications
|
|
307
356
|
* until the expression is irreducible, or max number of steps is reached.
|
|
@@ -310,15 +359,7 @@ export class Expr {
|
|
|
310
359
|
* @param {Expr} args
|
|
311
360
|
* @return {{expr: Expr, steps: number, final: boolean}}
|
|
312
361
|
*/
|
|
313
|
-
run(opt?:
|
|
314
|
-
max?: number;
|
|
315
|
-
steps?: number;
|
|
316
|
-
throw?: boolean;
|
|
317
|
-
} | Expr, ...args: Expr): {
|
|
318
|
-
expr: Expr;
|
|
319
|
-
steps: number;
|
|
320
|
-
final: boolean;
|
|
321
|
-
};
|
|
362
|
+
run(opt?: RunOptions | Expr, ...args: Expr[]): Run;
|
|
322
363
|
/**
|
|
323
364
|
* Execute step() while possible, yielding a brief description of events after each step.
|
|
324
365
|
* Mnemonics: like run() but slower.
|
|
@@ -327,11 +368,7 @@ export class Expr {
|
|
|
327
368
|
*/
|
|
328
369
|
walk(options?: {
|
|
329
370
|
max?: number;
|
|
330
|
-
}): IterableIterator<
|
|
331
|
-
final: boolean;
|
|
332
|
-
expr: Expr;
|
|
333
|
-
steps: number;
|
|
334
|
-
}>;
|
|
371
|
+
}): IterableIterator<Run>;
|
|
335
372
|
/**
|
|
336
373
|
* @desc True is the expressions are identical, false otherwise.
|
|
337
374
|
* Aliases are expanded.
|
|
@@ -375,7 +412,7 @@ export class Expr {
|
|
|
375
412
|
* @param {Expr} actual
|
|
376
413
|
* @param {string} comment
|
|
377
414
|
*/
|
|
378
|
-
expect(actual: Expr, comment?: string): void;
|
|
415
|
+
expect(actual: Expr | object, comment?: string): void;
|
|
379
416
|
/**
|
|
380
417
|
* @desc Returns string representation of the expression.
|
|
381
418
|
* Same as format() without options.
|
|
@@ -387,14 +424,14 @@ export class Expr {
|
|
|
387
424
|
* @param {boolean} [first] - whether this is the first term in a sequence
|
|
388
425
|
* @return {boolean}
|
|
389
426
|
*/
|
|
390
|
-
_braced(
|
|
427
|
+
_braced(_first?: boolean): boolean;
|
|
391
428
|
/**
|
|
392
429
|
* @desc Whether the expression can be printed without a space when followed by arg.
|
|
393
430
|
* @param {Expr} arg
|
|
394
431
|
* @returns {boolean}
|
|
395
432
|
* @private
|
|
396
433
|
*/
|
|
397
|
-
|
|
434
|
+
_unspaced(arg: Expr): boolean;
|
|
398
435
|
/**
|
|
399
436
|
* @desc Stringify the expression with fancy formatting options.
|
|
400
437
|
* Said options mostly include wrappers around various constructs in form of ['(', ')'],
|
|
@@ -428,18 +465,7 @@ export class Expr {
|
|
|
428
465
|
* @example foo.format({ inventory: { T } }) // use T as a named term, expand all others
|
|
429
466
|
*
|
|
430
467
|
*/
|
|
431
|
-
format(options?:
|
|
432
|
-
terse?: boolean;
|
|
433
|
-
html?: boolean;
|
|
434
|
-
brackets?: [string, string];
|
|
435
|
-
var?: [string, string];
|
|
436
|
-
lambda?: [string, string, string];
|
|
437
|
-
around?: [string, string];
|
|
438
|
-
redex?: [string, string];
|
|
439
|
-
inventory?: {
|
|
440
|
-
[x: string]: Expr;
|
|
441
|
-
};
|
|
442
|
-
}): string;
|
|
468
|
+
format(options?: FormatOptions): string;
|
|
443
469
|
/**
|
|
444
470
|
* @desc Internal method for format(), which performs the actual formatting.
|
|
445
471
|
* @param {Object} options
|
|
@@ -447,7 +473,7 @@ export class Expr {
|
|
|
447
473
|
* @returns {string}
|
|
448
474
|
* @private
|
|
449
475
|
*/
|
|
450
|
-
|
|
476
|
+
_format(options: RefinedFormatOptions, nargs: number): string;
|
|
451
477
|
/**
|
|
452
478
|
* @desc Returns a string representation of the expression tree, with indentation to show structure.
|
|
453
479
|
*
|
|
@@ -474,55 +500,48 @@ export class Expr {
|
|
|
474
500
|
* @desc Convert the expression to a JSON-serializable format.
|
|
475
501
|
* @returns {string}
|
|
476
502
|
*/
|
|
477
|
-
toJSON(): string;
|
|
478
|
-
}
|
|
479
|
-
export namespace Expr {
|
|
480
|
-
export { native };
|
|
481
|
-
export { control };
|
|
482
|
-
export namespace extras {
|
|
483
|
-
export { toposort };
|
|
484
|
-
}
|
|
503
|
+
toJSON(): string | object;
|
|
485
504
|
}
|
|
486
|
-
export class App extends Expr {
|
|
505
|
+
export declare class App extends Expr {
|
|
487
506
|
/**
|
|
488
507
|
* @desc Application of fun() to args.
|
|
489
508
|
* Never ever use new App(fun, arg) directly, use fun.apply(...args) instead.
|
|
490
509
|
* @param {Expr} fun
|
|
491
510
|
* @param {Expr} arg
|
|
492
511
|
*/
|
|
493
|
-
constructor(fun: Expr, arg: Expr);
|
|
494
|
-
arg: Expr;
|
|
495
512
|
fun: Expr;
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
513
|
+
arg: Expr;
|
|
514
|
+
final?: boolean;
|
|
515
|
+
constructor(fun: Expr, arg: Expr);
|
|
516
|
+
/** @property {boolean} [final] */
|
|
517
|
+
_traverse_descend(options: TraverseOptions, change: TraverseCallback): TraverseValue<Expr>;
|
|
518
|
+
any(predicate: (e: Expr) => boolean): boolean;
|
|
519
|
+
_fold<T>(initial: T, combine: (acc: T, expr: Expr) => TraverseValue<T>): TraverseValue<T>;
|
|
520
|
+
subst(search: Expr, replace: Expr): Expr | null;
|
|
500
521
|
/**
|
|
501
522
|
* @return {{expr: Expr, steps: number}}
|
|
502
523
|
*/
|
|
503
|
-
step():
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
_braced(first: any): boolean;
|
|
511
|
-
_format(options: any, nargs: any): string;
|
|
512
|
-
_unspaced(arg: any): boolean;
|
|
524
|
+
step(): Step;
|
|
525
|
+
invoke(arg: Expr): Invocation | null;
|
|
526
|
+
unroll(): Expr[];
|
|
527
|
+
diff(other: Expr, swap?: boolean): string | null;
|
|
528
|
+
_braced(first?: boolean): boolean;
|
|
529
|
+
_format(options: RefinedFormatOptions, nargs: number): string;
|
|
530
|
+
_unspaced(arg: Expr): boolean;
|
|
513
531
|
}
|
|
514
|
-
export class Named extends Expr {
|
|
532
|
+
export declare class Named extends Expr {
|
|
515
533
|
/**
|
|
516
534
|
* @desc An abstract class representing a term named 'name'.
|
|
517
535
|
*
|
|
518
536
|
* @param {String} name
|
|
519
537
|
*/
|
|
520
|
-
constructor(name: string);
|
|
521
538
|
name: string;
|
|
522
|
-
|
|
523
|
-
|
|
539
|
+
fancyName?: string;
|
|
540
|
+
constructor(name: string);
|
|
541
|
+
_unspaced(arg: Expr): boolean;
|
|
542
|
+
_format(options: RefinedFormatOptions, nargs: number): string;
|
|
524
543
|
}
|
|
525
|
-
export class FreeVar extends Named {
|
|
544
|
+
export declare class FreeVar extends Named {
|
|
526
545
|
/**
|
|
527
546
|
* @desc A named variable.
|
|
528
547
|
*
|
|
@@ -540,16 +559,38 @@ export class FreeVar extends Named {
|
|
|
540
559
|
* @param {string} name - name of the variable
|
|
541
560
|
* @param {any} scope - an object representing where the variable belongs to.
|
|
542
561
|
*/
|
|
543
|
-
|
|
562
|
+
scope?: object;
|
|
544
563
|
id: number;
|
|
545
|
-
|
|
546
|
-
diff(other:
|
|
547
|
-
subst(search:
|
|
564
|
+
constructor(name: string, scope?: object);
|
|
565
|
+
diff(other: Expr, swap?: boolean): string | null;
|
|
566
|
+
subst(search: Expr, replace: Expr): Expr | null;
|
|
567
|
+
_format(options: RefinedFormatOptions, nargs: number): string;
|
|
568
|
+
static global: string[];
|
|
548
569
|
}
|
|
549
|
-
export
|
|
550
|
-
|
|
570
|
+
export declare class Native extends Named {
|
|
571
|
+
/**
|
|
572
|
+
* @desc A named term with a known rewriting rule.
|
|
573
|
+
* 'impl' is a function with signature Expr => Expr => ... => Expr
|
|
574
|
+
* (see typedef Partial).
|
|
575
|
+
* This is how S, K, I, and company are implemented.
|
|
576
|
+
*
|
|
577
|
+
* Note that as of current something like a=>b=>b(a) is not possible,
|
|
578
|
+
* use full form instead: a=>b=>b.apply(a).
|
|
579
|
+
*
|
|
580
|
+
* @example new Native('K', x => y => x); // constant
|
|
581
|
+
* @example new Native('Y', function(f) { return f.apply(this.apply(f)); }); // self-application
|
|
582
|
+
*
|
|
583
|
+
* @param {String} name
|
|
584
|
+
* @param {Partial} impl
|
|
585
|
+
* @param {{note?: string, arity?: number, canonize?: boolean }} [opt]
|
|
586
|
+
*/
|
|
587
|
+
constructor(name: string, impl: (e: Expr) => Invocation, opt?: {
|
|
588
|
+
note?: string;
|
|
589
|
+
arity?: number;
|
|
590
|
+
canonize?: boolean;
|
|
591
|
+
});
|
|
551
592
|
}
|
|
552
|
-
export class Lambda extends Expr {
|
|
593
|
+
export declare class Lambda extends Expr {
|
|
553
594
|
/**
|
|
554
595
|
* @desc Lambda abstraction of arg over impl.
|
|
555
596
|
* Upon evaluation, all occurrences of 'arg' within 'impl' will be replaced
|
|
@@ -565,44 +606,31 @@ export class Lambda extends Expr {
|
|
|
565
606
|
* @param {FreeVar} arg
|
|
566
607
|
* @param {Expr} impl
|
|
567
608
|
*/
|
|
568
|
-
constructor(arg: FreeVar, impl: Expr);
|
|
569
609
|
arg: FreeVar;
|
|
570
610
|
impl: Expr;
|
|
571
|
-
|
|
572
|
-
invoke(arg:
|
|
573
|
-
_traverse_descend(options:
|
|
574
|
-
any(predicate:
|
|
575
|
-
_fold(initial:
|
|
576
|
-
subst(search:
|
|
577
|
-
diff(other:
|
|
578
|
-
_format(options:
|
|
579
|
-
_braced(first:
|
|
611
|
+
constructor(arg: FreeVar, impl: Expr);
|
|
612
|
+
invoke(arg: Expr): Expr;
|
|
613
|
+
_traverse_descend(options: TraverseOptions, change: TraverseCallback): TraverseValue<Expr>;
|
|
614
|
+
any(predicate: (e: Expr) => boolean): boolean;
|
|
615
|
+
_fold<T>(initial: T, combine: (acc: T, expr: Expr) => TraverseValue<T>): TraverseValue<T>;
|
|
616
|
+
subst(search: Expr, replace: Expr): Expr | null;
|
|
617
|
+
diff(other: Expr, swap?: boolean): string | null;
|
|
618
|
+
_format(options: RefinedFormatOptions, nargs: number): string;
|
|
619
|
+
_braced(first: boolean): boolean;
|
|
580
620
|
}
|
|
581
|
-
export class
|
|
621
|
+
export declare class Church extends Expr {
|
|
582
622
|
/**
|
|
583
|
-
* @desc
|
|
584
|
-
*
|
|
585
|
-
*
|
|
586
|
-
* This is how S, K, I, and company are implemented.
|
|
587
|
-
*
|
|
588
|
-
* Note that as of current something like a=>b=>b(a) is not possible,
|
|
589
|
-
* use full form instead: a=>b=>b.apply(a).
|
|
590
|
-
*
|
|
591
|
-
* @example new Native('K', x => y => x); // constant
|
|
592
|
-
* @example new Native('Y', function(f) { return f.apply(this.apply(f)); }); // self-application
|
|
593
|
-
*
|
|
594
|
-
* @param {String} name
|
|
595
|
-
* @param {Partial} impl
|
|
596
|
-
* @param {{note?: string, arity?: number, canonize?: boolean }} [opt]
|
|
623
|
+
* @desc Church numeral representing non-negative integer n:
|
|
624
|
+
* n f x = f(f(...(f x)...)) with f applied n times.
|
|
625
|
+
* @param {number} n
|
|
597
626
|
*/
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
invoke: Partial;
|
|
627
|
+
n: number;
|
|
628
|
+
constructor(n: number);
|
|
629
|
+
diff(other: Expr, swap?: boolean): string | null;
|
|
630
|
+
_unspaced(arg: Expr): boolean;
|
|
631
|
+
_format(options: RefinedFormatOptions, nargs: number): string;
|
|
604
632
|
}
|
|
605
|
-
export class Alias extends Named {
|
|
633
|
+
export declare class Alias extends Named {
|
|
606
634
|
/**
|
|
607
635
|
* @desc A named alias for an existing expression.
|
|
608
636
|
*
|
|
@@ -619,6 +647,9 @@ export class Alias extends Named {
|
|
|
619
647
|
* @param {Expr} impl
|
|
620
648
|
* @param {{canonize?: boolean, max?: number, maxArgs?: number, note?: string, terminal?: boolean}} [options]
|
|
621
649
|
*/
|
|
650
|
+
terminal?: boolean;
|
|
651
|
+
impl: Expr;
|
|
652
|
+
outdated?: boolean;
|
|
622
653
|
constructor(name: string, impl: Expr, options?: {
|
|
623
654
|
canonize?: boolean;
|
|
624
655
|
max?: number;
|
|
@@ -626,76 +657,35 @@ export class Alias extends Named {
|
|
|
626
657
|
note?: string;
|
|
627
658
|
terminal?: boolean;
|
|
628
659
|
});
|
|
629
|
-
impl: Expr;
|
|
630
|
-
terminal: any;
|
|
631
|
-
invoke: (arg: any) => any;
|
|
632
|
-
_traverse_descend(options: any, change: any): any;
|
|
633
|
-
any(predicate: any): any;
|
|
634
|
-
_fold(initial: any, combine: any): any;
|
|
635
|
-
subst(search: any, replace: any): any;
|
|
636
|
-
diff(other: any, swap?: boolean): any;
|
|
637
|
-
_braced(first: any): boolean;
|
|
638
|
-
}
|
|
639
|
-
export class Church extends Expr {
|
|
640
660
|
/**
|
|
641
|
-
* @
|
|
642
|
-
*
|
|
643
|
-
* @
|
|
661
|
+
* @property {boolean} [outdated] - whether the alias is outdated
|
|
662
|
+
* and should be replaced with its definition when encountered.
|
|
663
|
+
* @property {boolean} [terminal] - whether the alias should behave like a standalone term
|
|
664
|
+
* // TODO better name?
|
|
665
|
+
* @property {boolean} [proper] - whether the alias is a proper combinator (i.e. contains no free variables or constants)
|
|
666
|
+
* @property {number} [arity] - the number of arguments the alias waits for before expanding
|
|
667
|
+
* @property {Expr} [canonical] - equivalent lambda term.
|
|
644
668
|
*/
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
669
|
+
_traverse_descend(options: TraverseOptions, change: TraverseCallback): TraverseValue<Expr>;
|
|
670
|
+
any(predicate: (e: Expr) => boolean): boolean;
|
|
671
|
+
_fold<T>(initial: T, combine: (acc: T, expr: Expr) => TraverseValue<T>): TraverseValue<T>;
|
|
672
|
+
subst(search: Expr, replace: Expr): Expr | null;
|
|
673
|
+
/**
|
|
674
|
+
* @return {{expr: Expr, steps: number, changed: boolean}}
|
|
675
|
+
*/
|
|
676
|
+
step(): Step;
|
|
677
|
+
diff(other: Expr, swap?: boolean): string | null;
|
|
678
|
+
_braced(first: boolean): boolean;
|
|
679
|
+
_format(options: RefinedFormatOptions, nargs: number): string;
|
|
653
680
|
}
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
* @template T
|
|
664
|
-
* @typedef {T | TraverseControl<T> | null} TraverseValue
|
|
665
|
-
*/
|
|
666
|
-
/**
|
|
667
|
-
* @desc Control primitives for fold() and traverse() methods.
|
|
668
|
-
* @template T
|
|
669
|
-
* @type {{[name: string]: function(T): TraverseControl<T>}}
|
|
670
|
-
*/
|
|
671
|
-
declare const control: {
|
|
672
|
-
[name: string]: (arg0: T) => TraverseControl<T>;
|
|
673
|
-
};
|
|
674
|
-
/**
|
|
675
|
-
* @desc Sort a list in such a way that dependent terms come after the (named) terms they depend on.
|
|
676
|
-
* If env is given, only terms listed there are taken into account.
|
|
677
|
-
* If env is omitted, it will be implied from the list.
|
|
678
|
-
* If list is omitted, it will default to values of env.
|
|
679
|
-
* If just one term is given instead of a list, it will be coerced into a list.
|
|
680
|
-
*
|
|
681
|
-
* No terms outside env + list may ever appear in the result.
|
|
682
|
-
*
|
|
683
|
-
* The terms in env must be named and their names must match their keys.
|
|
684
|
-
*
|
|
685
|
-
* @param {Expr|Expr[]} list
|
|
686
|
-
* @param {{[s:string]: Named}} env
|
|
687
|
-
* @returns {{list: Expr[], env: {[s:string]: Named}}}
|
|
688
|
-
*
|
|
689
|
-
* @example
|
|
690
|
-
* const expr = ski.parse(src);
|
|
691
|
-
* toposort([expr], ski.getTerms()); // returns all terms appearing in Expr in correct order
|
|
692
|
-
*/
|
|
693
|
-
declare function toposort(list: Expr | Expr[], env: {
|
|
694
|
-
[s: string]: Named;
|
|
695
|
-
}): {
|
|
696
|
-
list: Expr[];
|
|
697
|
-
env: {
|
|
698
|
-
[s: string]: Named;
|
|
699
|
-
};
|
|
681
|
+
export declare const classes: {
|
|
682
|
+
Expr: typeof Expr;
|
|
683
|
+
App: typeof App;
|
|
684
|
+
Named: typeof Named;
|
|
685
|
+
FreeVar: typeof FreeVar;
|
|
686
|
+
Native: typeof Native;
|
|
687
|
+
Lambda: typeof Lambda;
|
|
688
|
+
Church: typeof Church;
|
|
689
|
+
Alias: typeof Alias;
|
|
700
690
|
};
|
|
701
691
|
export {};
|