tisp

tiny lisp
git clone git://edryd.org/tisp
Log | Files | Refs | LICENSE

commit 6a01925d467be41b6dbebc68dfd022b0955a7801
parent fc8e1d1720788b9124590788eb03d0f2ddc92441
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Sat, 12 Oct 2019 18:43:24 -0700

Don't keep evaluating list upon error

Diffstat:
tisp.c | 16++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/tisp.c b/tisp.c @@ -659,16 +659,16 @@ tisp_eval_list(Env env, Val v) { Val cur = mk_pair(NULL, env->none); Val ret = cur, ev; - for (; !nilp(v); v = cdr(v)) { + for (; !nilp(v); v = cdr(v), cur = cdr(cur)) { if (v->t != PAIR) { - if ((ev = tisp_eval(env, v))) - cdr(cur) = ev; + if (!(ev = tisp_eval(env, v))) + return NULL; + cdr(cur) = ev; return cdr(ret); } - if ((ev = tisp_eval(env, car(v)))) - cdr(cur) = ev; - cdr(cur) = mk_pair(cdr(cur), env->none); - cur = cdr(cur); + if (!(ev = tisp_eval(env, car(v)))) + return NULL; + cdr(cur) = mk_pair(ev, env->none); } cdr(cur) = env->nil; return cdr(ret); @@ -862,7 +862,7 @@ prim_eval(Env env, Val args) tsp_arg_num(args, "eval", 1); if (!(v = tisp_eval(env, car(args)))) return NULL; - return tisp_eval(env, v); + return (v = tisp_eval(env, v)) ? v : env->none; } /* test equality of all values given */