mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
(scm_append_x): Use iterative style, to avoid non-tail recursion.
This commit is contained in:
parent
6b69393dcc
commit
d46410989e
1 changed files with 18 additions and 12 deletions
|
@ -264,22 +264,28 @@ SCM_DEFINE (scm_append_x, "append!", 0, 0, 1,
|
||||||
"the mutated list.")
|
"the mutated list.")
|
||||||
#define FUNC_NAME s_scm_append_x
|
#define FUNC_NAME s_scm_append_x
|
||||||
{
|
{
|
||||||
|
SCM ret, *loc;
|
||||||
SCM_VALIDATE_REST_ARGUMENT (lists);
|
SCM_VALIDATE_REST_ARGUMENT (lists);
|
||||||
while (1) {
|
|
||||||
if (SCM_NULLP (lists)) {
|
if (SCM_NULLP (lists))
|
||||||
return SCM_EOL;
|
return SCM_EOL;
|
||||||
} else {
|
|
||||||
|
loc = &ret;
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
SCM arg = SCM_CAR (lists);
|
SCM arg = SCM_CAR (lists);
|
||||||
|
*loc = arg;
|
||||||
|
|
||||||
lists = SCM_CDR (lists);
|
lists = SCM_CDR (lists);
|
||||||
if (SCM_NULLP (lists)) {
|
if (SCM_NULLP (lists))
|
||||||
return arg;
|
return ret;
|
||||||
} else if (!SCM_NULL_OR_NIL_P (arg)) {
|
|
||||||
SCM_VALIDATE_CONS (SCM_ARG1, arg);
|
if (!SCM_NULL_OR_NIL_P (arg))
|
||||||
SCM_SETCDR (scm_last_pair (arg), scm_append_x (lists));
|
{
|
||||||
return arg;
|
SCM_VALIDATE_CONS (SCM_ARG1, arg);
|
||||||
}
|
loc = SCM_CDRLOC (scm_last_pair (arg));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue