summaryrefslogtreecommitdiff
path: root/libguile
diff options
context:
space:
mode:
authorKevin Ryde <user42@zip.com.au>2005-04-22 23:18:59 +0000
committerKevin Ryde <user42@zip.com.au>2005-04-22 23:18:59 +0000
commitb906b056e46e622d52c99c341aba252797970e87 (patch)
treef65e0b295b77935c7c944d5013f3a34ac6306034 /libguile
parent01adf598d9da709d5e54b46da4c2d62c314b0df7 (diff)
downloadguile-b906b056e46e622d52c99c341aba252797970e87.tar.gz
(scm_cons_star): Don't modify the rest list, it belongs to
the caller when cons* is reached through apply.
Diffstat (limited to 'libguile')
-rw-r--r--libguile/list.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/libguile/list.c b/libguile/list.c
index 9fffa228d..74f7f46cc 100644
--- a/libguile/list.c
+++ b/libguile/list.c
@@ -109,7 +109,7 @@ SCM_DEFINE (scm_list, "list", 0, 0, 1,
#undef FUNC_NAME
-SCM_DEFINE (scm_cons_star, "cons*", 1, 0, 1,
+SCM_DEFINE (scm_cons_star, "cons*", 1, 0, 1,
(SCM arg, SCM rest),
"Like @code{list}, but the last arg provides the tail of the\n"
"constructed list, returning @code{(cons @var{arg1} (cons\n"
@@ -119,18 +119,20 @@ SCM_DEFINE (scm_cons_star, "cons*", 1, 0, 1,
"Schemes and in Common LISP.")
#define FUNC_NAME s_scm_cons_star
{
+ SCM ret = SCM_EOL;
+ SCM *p = &ret;
+
SCM_VALIDATE_REST_ARGUMENT (rest);
- if (!scm_is_null (rest))
+
+ for ( ; scm_is_pair (rest); rest = SCM_CDR (rest))
{
- SCM prev = arg = scm_cons (arg, rest);
- while (!scm_is_null (SCM_CDR (rest)))
- {
- prev = rest;
- rest = SCM_CDR (rest);
- }
- SCM_SETCDR (prev, SCM_CAR (rest));
+ *p = scm_cons (arg, SCM_EOL);
+ p = SCM_CDRLOC (*p);
+ arg = SCM_CAR (rest);
}
- return arg;
+
+ *p = arg;
+ return ret;
}
#undef FUNC_NAME