From 7b3972e8326232db8cdf85ba252acdd65be2308c Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Apr 2017 01:13:03 +0900 Subject: [PATCH] bugfix: initial value of parameter must be registered to the top dynamic env --- lib/var.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/var.c b/lib/var.c index 8cfabe96..bf211624 100644 --- a/lib/var.c +++ b/lib/var.c @@ -40,10 +40,19 @@ var_call(pic_state *pic) pic_value pic_make_var(pic_state *pic, pic_value init, pic_value conv) { - pic_value var; + pic_value var, env = pic->dyn_env; var = pic_lambda(pic, var_call, 1, conv); - pic_call(pic, var, 1, init); + while (1) { + if (pic_nil_p(pic, pic_cdr(pic, env))) { /* top dyn env */ + if (! pic_false_p(pic, conv)) { + init = pic_call(pic, conv, 1, init); + } + pic_weak_set(pic, pic_car(pic, env), var, init); + break; + } + env = pic_cdr(pic, env); + } return var; }