REPL now uses beta reduction instead of transpiling.
This commit is contained in:
parent
2524ce8edf
commit
496e59be3c
19
src/repl.mjs
19
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));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue