mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-24 12:20:20 +02:00
fix take-right and drop-right for improper lists
* libguile/srfi-1.h: * libguile/srfi-1.c (scm_srfi1_drop_right, scm_srfi1_take_right): Remove these internal functions, replacing with Scheme implementations. * module/srfi/srfi-1.scm (take-right, drop-right): Add these impls from the reference code. They do the right thing for improper lists, according to the spec, but they diverge for circular lists. Oh well. * test-suite/tests/srfi-1.test ("drop-right", "take-right"): Add more tests.
This commit is contained in:
parent
335c8a89a2
commit
e7a81c7acd
4 changed files with 29 additions and 44 deletions
|
@ -568,28 +568,6 @@ SCM_DEFINE (scm_srfi1_delete_duplicates_x, "delete-duplicates!", 1, 1, 0,
|
|||
#undef FUNC_NAME
|
||||
|
||||
|
||||
SCM_DEFINE (scm_srfi1_drop_right, "drop-right", 2, 0, 0,
|
||||
(SCM lst, SCM n),
|
||||
"Return a new list containing all except the last @var{n}\n"
|
||||
"elements of @var{lst}.")
|
||||
#define FUNC_NAME s_scm_srfi1_drop_right
|
||||
{
|
||||
SCM tail = scm_list_tail (lst, n);
|
||||
SCM ret = SCM_EOL;
|
||||
SCM *rend = &ret;
|
||||
while (scm_is_pair (tail))
|
||||
{
|
||||
*rend = scm_cons (SCM_CAR (lst), SCM_EOL);
|
||||
rend = SCM_CDRLOC (*rend);
|
||||
|
||||
lst = SCM_CDR (lst);
|
||||
tail = SCM_CDR (tail);
|
||||
}
|
||||
SCM_ASSERT_TYPE (SCM_NULL_OR_NIL_P(tail), tail, SCM_ARG1, FUNC_NAME, "list");
|
||||
return ret;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
SCM_DEFINE (scm_srfi1_find, "find", 2, 0, 0,
|
||||
(SCM pred, SCM lst),
|
||||
"Return the first element of @var{lst} which satisfies the\n"
|
||||
|
@ -924,23 +902,6 @@ SCM_DEFINE (scm_srfi1_remove_x, "remove!", 2, 0, 0,
|
|||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
SCM_DEFINE (scm_srfi1_take_right, "take-right", 2, 0, 0,
|
||||
(SCM lst, SCM n),
|
||||
"Return a list containing the @var{n} last elements of\n"
|
||||
"@var{lst}.")
|
||||
#define FUNC_NAME s_scm_srfi1_take_right
|
||||
{
|
||||
SCM tail = scm_list_tail (lst, n);
|
||||
while (scm_is_pair (tail))
|
||||
{
|
||||
lst = SCM_CDR (lst);
|
||||
tail = SCM_CDR (tail);
|
||||
}
|
||||
SCM_ASSERT_TYPE (SCM_NULL_OR_NIL_P(tail), tail, SCM_ARG1, FUNC_NAME, "list");
|
||||
return lst;
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
|
||||
void
|
||||
scm_register_srfi_1 (void)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue