diff --git a/src/lambda-calculus.js b/src/lambda-calculus.js index e68604d..7479b76 100644 --- a/src/lambda-calculus.js +++ b/src/lambda-calculus.js @@ -42,7 +42,7 @@ class L { this.body = body; } free() { - const r = this.body.free?.() || new Set ; + const r = this.body?.free?.() || new Set ; r.delete(this.name); return r; } @@ -58,7 +58,7 @@ class A { this.left = left; this.right = right; } - free() { return union( this.left.free?.() || [] , this.right.free?.() || [] ); } + free() { return union( this.left?.free?.() || [] , this.right?.free?.() || [] ); } toString() { const left = this.left instanceof L ? `(${this.left})` : this.left ; const right = this.right instanceof V ? this.right : `(${this.right})` ; @@ -169,7 +169,7 @@ export function toInt(term) { function parse(code) { function parseTerm(env,code) { function wrap(name,term) { - const FV = term.free?.() || new Set ; FV.delete("()"); + const FV = term?.free?.() || new Set ; FV.delete("()"); if ( config.purity === "Let" ) return Array.from(FV).reduce( (tm,nm) => { if ( env.has(nm) ) {