list?(3scm) Scheme Programmer's Manual list?(3scm)

list? - check if an object is a list

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

(list? obj)

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.

pair?(3scm)

R4RS, IEEE Scheme, R5RS, R6RS, R7RS

The list? procedure first appeared in R4RS.

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://weinholt.se/scheme/manpages/.

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.
2022-03-23