From 496e59be3ce082c8ccafada470dc8d3d276761b7 Mon Sep 17 00:00:00 2001 From: trans_soup <> Date: Mon, 6 Nov 2023 22:18:59 +0100 Subject: [PATCH] REPL now uses beta reduction instead of transpiling. --- src/repl.mjs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/repl.mjs b/src/repl.mjs index 27e996d..339d488 100644 --- a/src/repl.mjs +++ b/src/repl.mjs @@ -4,6 +4,7 @@ import Expr from "./Expr.mjs"; import { parse_line } from "./parse.mjs"; import { compile_line } from "./compile.mjs"; import { transpile } from "./transpile.mjs"; +import { reduce } from "./reduce.mjs"; import readline from "node:readline"; @@ -41,8 +42,6 @@ function run (line) { } const parsed = parse_line(line); - const type = parsed.type; - const compiled = compile_line(env, parsed); if (!compiled.valid) { @@ -52,19 +51,11 @@ function run (line) { env = compiled.env; - if (type === Line.Expression) { - const expr_type = parsed.value.type; + if (parsed.type === Line.Expression) { + print(prettify(reduce(compiled.value))); - if (expr_type === Expr.Token || expr_type === Expr.Fn) { - print(prettify(compiled.value)); - } else if (expr_type === Expr.Application) { - const result = evaluate(compiled.value); - if (typeof result === "function") { - print(prettify(compiled.value)); - } else { - print(prettify(result)); - } - } + // js function that's equivalent to the entered lambda function. + // const fn = transpile(compiled.value)); } else { print(parsed.name + " = " + prettify(compiled.fn)); }