length - length of a list

LIBRARY

(import (rnrs))                     ;R6RS
(import (rnrs base))                ;R6RS
(import (scheme r5rs))              ;R7RS
(import (scheme base))              ;R7RS

SYNOPSIS

(length list)

DESCRIPTION

Returns the length of list.

IMPLEMENTATION NOTES

Implementations commonly use something like Floyd's cycle-finding algorithm to verify that the argument is truly a proper list.

RETURN VALUES

Returns a single exact integer which is the number of pairs that make up the list.

EXAMPLES

(length '(a b c))          => 3
(length '(a (b) (c d e)))  => 3
(length '())               => 0

APPLICATION USAGE

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).

COMPATIBILITY

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.

ERRORS

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.
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

cons(3scm), make-list(3scm), list-ref(3scm), vector-length(3scm).

STANDARDS

R4RS, IEEE Scheme, R5RS, R6RS, R7RS

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.