From 79dd1d99d8e7e85e8c5d3a968bd9f8fe47a4b7b0 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 1 Feb 2024 20:15:42 +0100 Subject: [PATCH] allow for nullish JS values as expressions fixes #99 better --- src/lambda-calculus.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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) ) {