list-ref - access an element of a list
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
(list-ref list k)
- Circular lists
R7RS explicitly allows
to be circular. R6RS also allows this, while also limiting the
implementation to only checking that
is a chain of pairs whose length is at least
Returns a single value; an object from the list.
(list-ref '(a b c d) 2) => c
(list-ref '(a b c d)
(exact (round 1.8)))
(define lst (list 'a 'b 'c 'd))
(set-cdr! (cdddr lst) lst) ;lst is now circular
(list-ref lst 4)
Except for different error behavior, this procedure works the same
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
The wrong number of arguments was passed or an argument was outside its domain.
must be a list whose length is at least
must be an exact nonnegative integer.
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.
This procedure first appeared in R2RS.
This page is part of the
It includes materials from the RnRS documents.
More information can be found at
Markup created by unroff 1.0sc, March 04, 2023.