make REPL output optional with each call to `run`.

This commit is contained in:
trans_soup 2023-11-06 23:54:30 +01:00
parent a3d013162c
commit 6fb482df27
1 changed files with 8 additions and 2 deletions

View File

@ -36,9 +36,13 @@ specials.set("!.env", _ => {
specials.set("!.clear", _ => console.clear());
specials.set("!.load combinators", _ => {
combinators.forEach(c => run(c, false));
});
function run (line) {
function run (line, output = true) {
if (specials.has(line)) {
specials.get(line)();
return;
@ -48,12 +52,14 @@ function run (line) {
const compiled = compile_line(env, parsed);
if (!compiled.valid) {
print("invalid line!");
if (output) print("invalid line!");
return;
}
env = compiled.env;
if (!output) return;
if (parsed.type === Line.Expression) {
print(prettify(reduce(compiled.value)));