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

SRFI-1: Rewrite `alist-copy' in Scheme.

This partially reverts commit b1fff4e793
(Sat Apr 2 2005).

* libguile/srfi-1.c (scm_srfi1_alist_copy): Remove.
* libguile/srfi-1.h (scm_srfi1_alist_copy): Remove declaration.

* module/srfi/srfi-1.scm (alist-copy): New procedure.
This commit is contained in:
Ludovic Courtès 2010-09-20 00:00:44 +02:00
parent cd99e21cd4
commit 194865d2f7
3 changed files with 9 additions and 36 deletions

View file

@ -104,41 +104,6 @@ list_copy_part (SCM lst, int count, SCM *dst)
#undef FUNC_NAME #undef FUNC_NAME
SCM_DEFINE (scm_srfi1_alist_copy, "alist-copy", 1, 0, 0,
(SCM alist),
"Return a copy of @var{alist}, copying both the pairs comprising\n"
"the list and those making the associations.")
#define FUNC_NAME s_scm_srfi1_alist_copy
{
SCM ret, *p, elem, c;
/* ret is the list to return. p is where to append to it, initially &ret
then SCM_CDRLOC of the last pair. */
ret = SCM_EOL;
p = &ret;
for ( ; scm_is_pair (alist); alist = SCM_CDR (alist))
{
elem = SCM_CAR (alist);
/* each element of alist must be a pair */
SCM_ASSERT_TYPE (scm_is_pair (elem), alist, SCM_ARG1, FUNC_NAME,
"association list");
c = scm_cons (scm_cons (SCM_CAR (elem), SCM_CDR (elem)), SCM_EOL);
*p = c;
p = SCM_CDRLOC (c);
}
/* alist must be a proper list */
SCM_ASSERT_TYPE (SCM_NULL_OR_NIL_P (alist), alist, SCM_ARG1, FUNC_NAME,
"association list");
return ret;
}
#undef FUNC_NAME
SCM_DEFINE (scm_srfi1_append_reverse, "append-reverse", 2, 0, 0, SCM_DEFINE (scm_srfi1_append_reverse, "append-reverse", 2, 0, 0,
(SCM revhead, SCM tail), (SCM revhead, SCM tail),
"Reverse @var{rev-head}, append @var{tail} to it, and return the\n" "Reverse @var{rev-head}, append @var{tail} to it, and return the\n"

View file

@ -24,7 +24,6 @@
#include "libguile/__scm.h" #include "libguile/__scm.h"
SCM_INTERNAL SCM scm_srfi1_alist_copy (SCM alist);
SCM_INTERNAL SCM scm_srfi1_append_reverse (SCM revhead, SCM tail); SCM_INTERNAL SCM scm_srfi1_append_reverse (SCM revhead, SCM tail);
SCM_INTERNAL SCM scm_srfi1_append_reverse_x (SCM revhead, SCM tail); SCM_INTERNAL SCM scm_srfi1_append_reverse_x (SCM revhead, SCM tail);
SCM_INTERNAL SCM scm_srfi1_concatenate (SCM lstlst); SCM_INTERNAL SCM scm_srfi1_concatenate (SCM lstlst);

View file

@ -664,6 +664,15 @@ CLIST1 ... CLISTN, that satisfies PRED."
(define alist-cons acons) (define alist-cons acons)
(define (alist-copy alist)
"Return a copy of ALIST, copying both the pairs comprising the list
and those making the associations."
(let lp ((a alist)
(rl '()))
(if (null? a)
(reverse! rl)
(lp (cdr a) (alist-cons (caar a) (cdar a) rl)))))
(define* (alist-delete key alist #:optional (k= equal?)) (define* (alist-delete key alist #:optional (k= equal?))
(let lp ((a alist) (rl '())) (let lp ((a alist) (rl '()))
(if (null? a) (if (null? a)