[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: append! non-tail recursion
From: |
Kevin Ryde |
Subject: |
Re: append! non-tail recursion |
Date: |
Thu, 15 Apr 2004 10:22:07 +1000 |
User-agent: |
Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux) |
I ended up with this change,
* list.c (scm_append_x): Use iterative style, to avoid non-tail
recursion.
New code:
SCM_DEFINE (scm_append_x, "append!", 0, 0, 1,
(SCM lists),
"A destructive version of @code{append} (@pxref{Pairs and\n"
"Lists,,,r5rs, The Revised^5 Report on Scheme}). The cdr field\n"
"of each list's final pair is changed to point to the head of\n"
"the next list, so no consing is performed. Return\n"
"the mutated list.")
#define FUNC_NAME s_scm_append_x
{
SCM ret, *loc;
SCM_VALIDATE_REST_ARGUMENT (lists);
if (SCM_NULLP (lists))
return SCM_EOL;
loc = &ret;
for (;;)
{
SCM arg = SCM_CAR (lists);
*loc = arg;
lists = SCM_CDR (lists);
if (SCM_NULLP (lists))
return ret;
if (!SCM_NULL_OR_NIL_P (arg))
{
SCM_VALIDATE_CONS (SCM_ARG1, arg);
loc = SCM_CDRLOC (scm_last_pair (arg));
}
}
}
#undef FUNC_NAME
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: append! non-tail recursion,
Kevin Ryde <=