tisp

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

commit cf612e4f5790a4a5b1fd9d79a20f1ab5be3cc2bd
parent f123a7fce8147be6110d4c054fa47a380f6f1a72
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Sun, 25 Mar 2018 23:51:50 -0700

Add cond primitive

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

diff --git a/tisp.c b/tisp.c @@ -593,6 +593,18 @@ prim_quote(Hash env, Val args) } static Val +prim_cond(Hash env, Val args) +{ + Val v, cond; + for (v = args; !nilp(v); v = cdr(v)) + if (!(cond = tisp_eval(env, car(car(v))))) + return NULL; + else if (vals_eq(cond, &t)) + return tisp_eval(env, car(cdr(car(v)))); + return &nil; +} + +static Val prim_lambda(Hash env, Val args) { if (list_len(args) < 2 || car(args)->t != PAIR) @@ -636,6 +648,7 @@ init_env(void) hash_add(h, "cons", mk_prim(prim_cons)); hash_add(h, "=", mk_prim(prim_eq)); hash_add(h, "quote", mk_prim(prim_quote)); + hash_add(h, "cond", mk_prim(prim_cond)); hash_add(h, "lambda", mk_prim(prim_lambda)); hash_add(h, "define", mk_prim(prim_define)); hash_add(h, "+", mk_prim(prim_add));