From a6f3fc96e646c4fdbbd8e263b1b2d6fc656a4706 Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 13 Jul 2021 21:46:15 +0100 Subject: [PATCH] Fixed bug where all func calls require an argument Certain I/O functions (like `inp` or `repl`) do not need arguments, but previously all functions required at least one argument to called correctly (i.e. `(inp 0)` or `(repl "banana")`). Now, these can be called as intended: `(inp)` or `(repl)`. --- src/env.c | 9 +++++++-- src/examples/repl.pbl | 8 ++++---- src/pebblisp.c | 11 ++++------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/env.c b/src/env.c index 99239ad..25356a1 100644 --- a/src/env.c +++ b/src/env.c @@ -15,8 +15,13 @@ Object fetchFromEnvironment(const char *name, struct Environment *env) if(!env) return errorObject(NULL_ENV); - if(env->size == 0) - return errorObject(EMPTY_ENV); + if(env->size == 0) { + if (env->outer) { + return fetchFromEnvironment(name, env->outer); + } else { + return errorObject(EMPTY_ENV); + } + } for(int i = 0; i < env->size; i++) { if(env->strings[i] == NULL) { diff --git a/src/examples/repl.pbl b/src/examples/repl.pbl index 0445130..0ab0312 100755 --- a/src/examples/repl.pbl +++ b/src/examples/repl.pbl @@ -1,10 +1,10 @@ #!/usr/bin/pl -(def repl (fn (_) ( +(def repl (fn () ( (prn "pebblisp::> ") - (def input (inp 0)) + (def input (inp)) (if (= input "q") () ( (prnl (eval input)) - (repl 0))) + (repl))) ))) -(repl 0) +(repl) diff --git a/src/pebblisp.c b/src/pebblisp.c index 3587555..28cd455 100644 --- a/src/pebblisp.c +++ b/src/pebblisp.c @@ -162,6 +162,10 @@ Object listEvalFunc( const int length, struct Environment *env) { + if(length == 0) { + return function->func(boolObject(0), boolObject(0), env); + } + Object rest[length]; evalForms(rest, list->list->forward, env); @@ -244,13 +248,6 @@ Object evalList(const Object *obj, struct Environment *env) return cloneObject(*obj); } - if(evalLength == 1) { - if(listLength(obj->list) == 0) { - return cloneObject(*obj); - } - return startList(eval(obj->list, env)); - } - Object *first_form = obj->list; { // Try to eval built-ins