detect (some) terms without a normal form.
This commit is contained in:
parent
1001dfb152
commit
7e928a7a5f
|
@ -1,12 +1,23 @@
|
|||
function serialize (expr) {
|
||||
return Array.isArray(expr)
|
||||
? "(" + expr.map(serialize).join(",") + ")"
|
||||
: expr;
|
||||
}
|
||||
|
||||
export function reduce (expr, max_steps = 1000) {
|
||||
if (!is_application(expr)) {
|
||||
return expr;
|
||||
}
|
||||
|
||||
let result = reduce_single(expr);
|
||||
const visited = new Map();
|
||||
|
||||
// trampoline
|
||||
for (let step = 0; step < max_steps; step++) {
|
||||
const key = serialize(result);
|
||||
|
||||
if (visited.has(key)) return result;
|
||||
visited.set(key, true);
|
||||
result = reduce_single(result);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue