mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-09 21:40:33 +02:00
(scm_srfi1_count, scm_srfi1_filter_map): Don't modify the
rest argument, that belongs to the caller when reached from apply. Use a temp vector like scm_srfi1_for_each.
This commit is contained in:
parent
8cb2eff840
commit
eccd308a5b
1 changed files with 28 additions and 24 deletions
|
@ -198,28 +198,30 @@ SCM_DEFINE (scm_srfi1_count, "count", 2, 0, 1,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* three or more lists */
|
/* three or more lists */
|
||||||
SCM lstlst, args, l, a;
|
SCM vec, args, a;
|
||||||
|
size_t len, i;
|
||||||
|
|
||||||
/* lstlst is a list of the list arguments */
|
/* vec is the list arguments */
|
||||||
lstlst = scm_cons (list1, rest);
|
vec = scm_vector (scm_cons (list1, rest));
|
||||||
|
len = SCM_SIMPLE_VECTOR_LENGTH (vec);
|
||||||
|
|
||||||
/* args is the argument list to pass to pred, same length as lstlst,
|
/* args is the argument list to pass to pred, same length as vec,
|
||||||
re-used for each call */
|
re-used for each call */
|
||||||
args = scm_list_copy (lstlst);
|
args = scm_make_list (SCM_I_MAKINUM (len), SCM_UNDEFINED);
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
/* first elem of each list in lstlst into args, and step those
|
/* first elem of each list in vec into args, and step those
|
||||||
lstlst entries onto their next element */
|
vec entries onto their next element */
|
||||||
for (l = lstlst, a = args, argnum = 2;
|
for (i = 0, a = args, argnum = 2;
|
||||||
scm_is_pair (l);
|
i < len;
|
||||||
l = SCM_CDR (l), a = SCM_CDR (a), argnum++)
|
i++, a = SCM_CDR (a), argnum++)
|
||||||
{
|
{
|
||||||
lst = SCM_CAR (l); /* list argument */
|
lst = SCM_SIMPLE_VECTOR_REF (vec, i); /* list argument */
|
||||||
if (! scm_is_pair (lst))
|
if (! scm_is_pair (lst))
|
||||||
goto check_lst_and_done;
|
goto check_lst_and_done;
|
||||||
SCM_SETCAR (a, SCM_CAR (lst)); /* arg for pred */
|
SCM_SETCAR (a, SCM_CAR (lst)); /* arg for pred */
|
||||||
SCM_SETCAR (l, SCM_CDR (lst)); /* keep rest of lst */
|
SCM_SIMPLE_VECTOR_SET (vec, i, SCM_CDR (lst)); /* rest of lst */
|
||||||
}
|
}
|
||||||
|
|
||||||
count += scm_is_true (scm_apply (pred, args, SCM_EOL));
|
count += scm_is_true (scm_apply (pred, args, SCM_EOL));
|
||||||
|
@ -623,28 +625,30 @@ SCM_DEFINE (scm_srfi1_filter_map, "filter-map", 2, 0, 1,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* three or more lists */
|
/* three or more lists */
|
||||||
SCM lstlst, args, l, a;
|
SCM vec, args, a;
|
||||||
|
size_t len, i;
|
||||||
|
|
||||||
/* lstlst is a list of the list arguments */
|
/* vec is the list arguments */
|
||||||
lstlst = scm_cons (list1, rest);
|
vec = scm_vector (scm_cons (list1, rest));
|
||||||
|
len = SCM_SIMPLE_VECTOR_LENGTH (vec);
|
||||||
|
|
||||||
/* args is the argument list to pass to proc, same length as lstlst,
|
/* args is the argument list to pass to proc, same length as vec,
|
||||||
re-used for each call */
|
re-used for each call */
|
||||||
args = scm_list_copy (lstlst);
|
args = scm_make_list (SCM_I_MAKINUM (len), SCM_UNDEFINED);
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
/* first elem of each list in lstlst into args, and step those
|
/* first elem of each list in vec into args, and step those
|
||||||
lstlst entries onto their next element */
|
vec entries onto their next element */
|
||||||
for (l = lstlst, a = args, argnum = 2;
|
for (i = 0, a = args, argnum = 2;
|
||||||
scm_is_pair (l);
|
i < len;
|
||||||
l = SCM_CDR (l), a = SCM_CDR (a), argnum++)
|
i++, a = SCM_CDR (a), argnum++)
|
||||||
{
|
{
|
||||||
lst = SCM_CAR (l); /* list argument */
|
lst = SCM_SIMPLE_VECTOR_REF (vec, i); /* list argument */
|
||||||
if (! scm_is_pair (lst))
|
if (! scm_is_pair (lst))
|
||||||
goto check_lst_and_done;
|
goto check_lst_and_done;
|
||||||
SCM_SETCAR (a, SCM_CAR (lst)); /* arg for proc */
|
SCM_SETCAR (a, SCM_CAR (lst)); /* arg for proc */
|
||||||
SCM_SETCAR (l, SCM_CDR (lst)); /* keep rest of lst */
|
SCM_SIMPLE_VECTOR_SET (vec, i, SCM_CDR (lst)); /* rest of lst */
|
||||||
}
|
}
|
||||||
|
|
||||||
elem = scm_apply (proc, args, SCM_EOL);
|
elem = scm_apply (proc, args, SCM_EOL);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue