summaryrefslogtreecommitdiff
path: root/lisp.c
diff options
context:
space:
mode:
Diffstat (limited to 'lisp.c')
-rw-r--r--lisp.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/lisp.c b/lisp.c
index 22e90b5..da0a5f6 100644
--- a/lisp.c
+++ b/lisp.c
@@ -265,21 +265,26 @@ value *eval_pair(env *e, value *v) {
}
if (head_eval->type == VT_LAMBDA) {
- return apply(head_eval, tail);
+ return apply(e, head_eval, tail);
}
return v;
}
-value *apply(value *lval, value *args) {
- env *sub_env = env_create(lval->as.lambda.env);
+value *apply(env *e, value *lval, value *args) {
+ env *sub_env = env_create(e);
value *params = lval->as.lambda.params;
value *arg = args;
while (params->type == VT_PAIR && arg->type == VT_PAIR) {
- env_define(sub_env,
- car(params)->as.sym,
- eval(lval->as.lambda.env, car(arg)));
+ if (car(params)->type != VT_SYMBOL) {
+ printf("not a symbol: ");
+ println_value(car(params));
+ return make_nil();
+ }
+
+ value *arg_eval = eval(e, car(arg));
+ env_define(sub_env, car(params)->as.sym, arg_eval);
params = cdr(params);
arg = cdr(arg);
}