Try to skip double evaluations in list

This commit is contained in:
Sage Vaillancourt 2020-11-04 15:19:08 -05:00
parent 9da87f5674
commit 31fcf0c2d8
1 changed files with 11 additions and 4 deletions

View File

@ -197,13 +197,15 @@ Object listEvalLambda(
env env
); );
Object ret = eval(&lambda->lambda->body, &newEnv); Object ret = eval(&lambda->lambda->body, &newEnv);
deleteEnv(&newEnv); deleteEnv(&newEnv);
cleanObject(lambda); cleanObject(lambda);
Object *t = tail(&ret); Object *t = tail(&ret);
if(t) { if(t) {
// cleanObject(&ret); Object o = cloneObject(*t);
return cloneObject(*t); cleanObject(&ret);
return o;
} }
return ret; return ret;
} }
@ -259,8 +261,13 @@ Object evalList(const Object *obj, struct Environment *env)
default: { // Return list with each element evaluated default: { // Return list with each element evaluated
Object list = listObject(); Object list = listObject();
int i = 0;
nf_addToList(&list, first_eval);
FOR_POINTER_IN_LIST(obj) { FOR_POINTER_IN_LIST(obj) {
nf_addToList(&list, eval(POINTER, env)); if(i != 0) {
nf_addToList(&list, eval(POINTER, env));
}
i++;
} }
return list; return list;
} }
@ -491,7 +498,7 @@ Object print(Object p, Object ignore, struct Environment *env)
p = cloneObject(p); p = cloneObject(p);
p = eval(&p, env); p = eval(&p, env);
_printObj(&p, 0); _printObj(&p, 0);
return p; return numberObject(0);
} }
Object pChar(Object c, Object i1, struct Environment *i2) Object pChar(Object c, Object i1, struct Environment *i2)