reverse - reverse a list
LIBRARY
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
SYNOPSIS
(reverse list)
DESCRIPTION
Returns a newly allocated list consisting of the elements of
list
in reverse order.
- R6RS
-
Implementations must verify that
list
is a proper list.
IMPLEMENTATION NOTES
- Chibi Scheme
-
Circular lists are not detected. Improper lists are handled as if they
were terminated by the last non-pair in the chain.
RETURN VALUES
Returns a single value; a list.
EXAMPLES
(reverse '(a b c))
=> (c b a)
(reverse '(a (b c) d (e (f))))
=> ((e (f)) d (b c) a)
COMPATIBILITY
In R6RS implementations the following code is guaranteed to raise an
exception. Non-R6RS implementations will commonly detect the problem
or loop until the process runs out of memory.
(import (rnrs) (rnrs mutable-pairs))
(let ((xs (list 1 2)))
(set-cdr! (cdr xs) xs)
(reverse xs))
ERRORS
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
-
The wrong number of arguments was passed or the argument was not a proper list.
- R7RS
-
The assertions described above are errors.
Implementations may signal an error, extend the procedure's
domain of definition to include such arguments,
or fail catastrophically.
SEE ALSO
list(3scm),
append(3scm),
list-copy(3scm)
STANDARDS
R4RS,
IEEE Scheme,
R5RS,
R6RS,
R7RS
HISTORY
This procedure was already present in the first versions of Scheme,
even those running on MacLisp. It was also present in LISP 1.5.
AUTHORS
This page is part of the
scheme-manpages
project.
It includes materials from the RnRS documents.
More information can be found at
https://github.com/schemedoc/manpages/
.
Markup created by unroff 1.0sc, March 04, 2023.