list? - check if an object is a list
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
Returns #t if obj is a list, #f otherwise. By definition,
all lists are chains of pairs that have finite length and are terminated by
the empty list.
This procedure is expected to run in time linear to the number of elements in
the list. Implementations can be expected to use an algorithm like Floyd's
cycle-finding algorithm ("tortoise and hare"), which handles the
case of circular lists created with set-cdr!(3scm).
Returns a boolean object.
(list? '(a b c)) => #t
(list? '()) => #t
(list? '(a . b)) => #f
(let ((x (list 'a)))
(set-cdr! x x)
(list? x)) => #f
The list? procedure is identical in all revisions of the Scheme reports.
IEEE Scheme explicitly mentions the case of circular structures.
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
- The wrong number of arguments was passed.
- 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.
R4RS, IEEE Scheme, R5RS, R6RS, R7RS
The list? procedure first appeared in R4RS.
A fairly common mistake is to call list? when destructuring an object,
e.g. immediately before using car(3scm) or cdr(3scm). Use
pair?(3scm) instead.