commit 4ca5065cfc87fcbae0e2e868ebe2b6974e98ceea
parent 1390aaf4d28e32211dedec07aa0d961e16f98404
Author: Andres Navarro <canavarro82@gmail.com>
Date: Mon, 28 Mar 2011 15:57:14 -0300
Added $letrec to the ground environment.
Diffstat:
3 files changed, 24 insertions(+), 3 deletions(-)
diff --git a/src/kgenvironments.c b/src/kgenvironments.c
@@ -250,7 +250,28 @@ void make_kernel_standard_environment(klisp_State *K, TValue *xparams,
/* TODO */
/* 6.7.6 $letrec* */
-/* TODO */
+void Sletrec(klisp_State *K, TValue *xparams, TValue ptree, TValue denv)
+{
+ /*
+ ** xparams[0]: symbol name
+ */
+ TValue sname = xparams[0];
+ char *name = ksymbol_buf(sname);
+ bind_al1p(K, name, ptree, bindings, body);
+
+ TValue exprs;
+ TValue bptree = split_check_let_bindings(K, name, bindings, &exprs, false);
+ int32_t dummy;
+ UNUSED(check_list(K, name, true, body, &dummy));
+ body = copy_es_immutable_h(K, name, body, false);
+
+ TValue new_env = kmake_environment(K, denv);
+ TValue new_cont =
+ kmake_continuation(K, kget_cc(K), KNIL, KNIL, do_let, 7, sname,
+ bptree, KNIL, KNIL, new_env, b2tv(false), body);
+ kset_cc(K, new_cont);
+ ktail_eval(K, kcons(K, K->list_app, exprs), new_env);
+}
/* Helper for $let-redirect */
void do_let_redirect(klisp_State *K, TValue *xparams, TValue obj)
diff --git a/src/kgenvironments.h b/src/kgenvironments.h
@@ -53,7 +53,7 @@ void make_kernel_standard_environment(klisp_State *K, TValue *xparams,
/* TODO */
/* 6.7.5 $letrec */
-/* TODO */
+void Sletrec(klisp_State *K, TValue *xparams, TValue ptree, TValue denv);
/* 6.7.6 $letrec* */
/* TODO */
diff --git a/src/kground.c b/src/kground.c
@@ -455,7 +455,7 @@ void kinit_ground_env(klisp_State *K)
/* TODO */
/* 6.7.5 $letrec */
- /* TODO */
+ add_operative(K, ground_env, "$letrec", Sletrec, 1, symbol);
/* 6.7.6 $letrec* */
/* TODO */