core: reverse!: Handle empty list.

* src/mes.c (reverse_x_): Handle empty list.
* tests/scm.test ("reverse! ()"): Test it.
This commit is contained in:
Jan Nieuwenhuizen 2018-04-29 18:14:01 +02:00
parent dc24a7f76f
commit 41fe739463
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
2 changed files with 4 additions and 1 deletions

View file

@ -661,7 +661,7 @@ append_reverse (SCM x, SCM y)
SCM SCM
reverse_x_ (SCM x, SCM t) reverse_x_ (SCM x, SCM t)
{ {
if (TYPE (x) != TPAIR) if (x != cell_nil && TYPE (x) != TPAIR)
error (cell_symbol_not_a_pair, cons (x, cell_reverse_x_)); error (cell_symbol_not_a_pair, cons (x, cell_reverse_x_));
SCM r = t; SCM r = t;
while (x != cell_nil) while (x != cell_nil)

View file

@ -137,6 +137,9 @@ exit $?
(reverse! list) (reverse! list)
list)) list))
(pass-if-equal "reverse! ()" '()
(reverse! '()))
(pass-if "cond-expand" (sequal? (cond-expand (foobar #f) (mes (display ": pass: *YAY*") 'mes) (guile (display ": pass: *GUILE*") 'mes)) 'mes)) (pass-if "cond-expand" (sequal? (cond-expand (foobar #f) (mes (display ": pass: *YAY*") 'mes) (guile (display ": pass: *GUILE*") 'mes)) 'mes))
(pass-if "apply identity" (seq? (apply identity '(0)) 0)) (pass-if "apply identity" (seq? (apply identity '(0)) 0))