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