list? - check if an object is a list

LIBRARY

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

SYNOPSIS

(list? obj)

DESCRIPTION

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.

IMPLEMENTATION NOTES

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

RETURN VALUES

Returns a boolean object.

EXAMPLES

(list? '(a b c))  => #t

(list? '())       => #t

(list? '(a . b))  => #f

(let ((x (list 'a)))
  (set-cdr! x x)
  (list? x))      => #f

COMPATIBILITY

The list? procedure is identical in all revisions of the Scheme reports. IEEE Scheme explicitly mentions the case of circular structures.

ERRORS

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.

SEE ALSO

pair?(3scm)

STANDARDS

R4RS, IEEE Scheme, R5RS, R6RS, R7RS

HISTORY

The list? procedure first appeared in R4RS.

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

BUGS

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.


Markup created by unroff 1.0sc,    March 04, 2023.