1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00

(scm_append_x): Use iterative style, to avoid non-tail recursion.

This commit is contained in:
Kevin Ryde 2004-04-15 00:23:57 +00:00
parent 6b69393dcc
commit d46410989e

View file

@ -264,20 +264,26 @@ 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)) {
if (!SCM_NULL_OR_NIL_P (arg))
{
SCM_VALIDATE_CONS (SCM_ARG1, arg); SCM_VALIDATE_CONS (SCM_ARG1, arg);
SCM_SETCDR (scm_last_pair (arg), scm_append_x (lists)); loc = SCM_CDRLOC (scm_last_pair (arg));
return arg;
}
} }
} }
} }