mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
Improve error reporting in 'append!'
* libguile/list.c (scm_append_x): Report correct argument number when validating arguments. Validate that the last cdr of each argument is null or nil. Rename formal rest argument from 'lists' to 'args'. * test-suite/tests/list.test (append!): Update tests to expect correct handling of improper lists.
This commit is contained in:
parent
88644a10d8
commit
226a56a3d4
2 changed files with 13 additions and 10 deletions
|
@ -267,7 +267,7 @@ SCM_DEFINE (scm_append, "append", 0, 0, 1,
|
||||||
|
|
||||||
|
|
||||||
SCM_DEFINE (scm_append_x, "append!", 0, 0, 1,
|
SCM_DEFINE (scm_append_x, "append!", 0, 0, 1,
|
||||||
(SCM lists),
|
(SCM args),
|
||||||
"A destructive version of @code{append} (@pxref{Pairs and\n"
|
"A destructive version of @code{append} (@pxref{Pairs and\n"
|
||||||
"Lists,,,r5rs, The Revised^5 Report on Scheme}). The cdr field\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"
|
"of each list's final pair is changed to point to the head of\n"
|
||||||
|
@ -276,26 +276,29 @@ SCM_DEFINE (scm_append_x, "append!", 0, 0, 1,
|
||||||
#define FUNC_NAME s_scm_append_x
|
#define FUNC_NAME s_scm_append_x
|
||||||
{
|
{
|
||||||
SCM ret, *loc;
|
SCM ret, *loc;
|
||||||
SCM_VALIDATE_REST_ARGUMENT (lists);
|
int argnum = 1;
|
||||||
|
SCM_VALIDATE_REST_ARGUMENT (args);
|
||||||
|
|
||||||
if (scm_is_null (lists))
|
if (scm_is_null (args))
|
||||||
return SCM_EOL;
|
return SCM_EOL;
|
||||||
|
|
||||||
loc = &ret;
|
loc = &ret;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
SCM arg = SCM_CAR (lists);
|
SCM arg = SCM_CAR (args);
|
||||||
*loc = arg;
|
*loc = arg;
|
||||||
|
|
||||||
lists = SCM_CDR (lists);
|
args = SCM_CDR (args);
|
||||||
if (scm_is_null (lists))
|
if (scm_is_null (args))
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (!SCM_NULL_OR_NIL_P (arg))
|
if (!SCM_NULL_OR_NIL_P (arg))
|
||||||
{
|
{
|
||||||
SCM_VALIDATE_CONS (SCM_ARG1, arg);
|
SCM_VALIDATE_CONS (argnum, arg);
|
||||||
loc = SCM_CDRLOC (scm_last_pair (arg));
|
loc = SCM_CDRLOC (scm_last_pair (arg));
|
||||||
|
SCM_VALIDATE_NULL_OR_NIL (argnum, *loc);
|
||||||
}
|
}
|
||||||
|
argnum++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#undef FUNC_NAME
|
#undef FUNC_NAME
|
||||||
|
|
|
@ -439,15 +439,15 @@
|
||||||
|
|
||||||
(with-test-prefix "wrong argument"
|
(with-test-prefix "wrong argument"
|
||||||
|
|
||||||
(expect-fail-exception "improper list and empty list"
|
(pass-if-exception "improper list and empty list"
|
||||||
exception:wrong-type-arg
|
exception:wrong-type-arg
|
||||||
(append! (cons 1 2) '()))
|
(append! (cons 1 2) '()))
|
||||||
|
|
||||||
(expect-fail-exception "improper list and list"
|
(pass-if-exception "improper list and list"
|
||||||
exception:wrong-type-arg
|
exception:wrong-type-arg
|
||||||
(append! (cons 1 2) (list 3 4)))
|
(append! (cons 1 2) (list 3 4)))
|
||||||
|
|
||||||
(expect-fail-exception "list, improper list and list"
|
(pass-if-exception "list, improper list and list"
|
||||||
exception:wrong-type-arg
|
exception:wrong-type-arg
|
||||||
(append! (list 1 2) (cons 3 4) (list 5 6)))
|
(append! (list 1 2) (cons 3 4) (list 5 6)))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue