length - length of a list
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
Returns the length of list.
Implementations commonly use something like Floyd's cycle-finding
algorithm to verify that the argument is truly a proper list.
Returns a single exact integer which is the number of pairs that make
up the list.
(length '(a b c)) => 3
(length '(a (b) (c d e))) => 3
(length '()) => 0
The length procedure often appears in code that deals with an
arbitrary number of objects stored in a list, and where the length
of the list is needed during serialization. It also tends to appear
in code that destructures lists, but in such cases it may be better
to use a pattern matching library such as (chibi match).
R6RS requires implementations to verify that the argument is a proper
list. R7RS does not require this and as a consequence implementations
may misbehave if the argument is not a proper list, or go into a
non-terminating loop if the argument is a cyclical list.
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.
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 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.