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,20 +264,26 @@ SCM_DEFINE (scm_append_x, "append!", 0, 0, 1,
|
|||
"the mutated list.")
|
||||
#define FUNC_NAME s_scm_append_x
|
||||
{
|
||||
SCM ret, *loc;
|
||||
SCM_VALIDATE_REST_ARGUMENT (lists);
|
||||
while (1) {
|
||||
if (SCM_NULLP (lists)) {
|
||||
|
||||
if (SCM_NULLP (lists))
|
||||
return SCM_EOL;
|
||||
} else {
|
||||
|
||||
loc = &ret;
|
||||
for (;;)
|
||||
{
|
||||
SCM arg = SCM_CAR (lists);
|
||||
*loc = arg;
|
||||
|
||||
lists = SCM_CDR (lists);
|
||||
if (SCM_NULLP (lists)) {
|
||||
return arg;
|
||||
} else if (!SCM_NULL_OR_NIL_P (arg)) {
|
||||
if (SCM_NULLP (lists))
|
||||
return ret;
|
||||
|
||||
if (!SCM_NULL_OR_NIL_P (arg))
|
||||
{
|
||||
SCM_VALIDATE_CONS (SCM_ARG1, arg);
|
||||
SCM_SETCDR (scm_last_pair (arg), scm_append_x (lists));
|
||||
return arg;
|
||||
}
|
||||
loc = SCM_CDRLOC (scm_last_pair (arg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue