Lists

Table of Contents

Lists are built up from cons cells, which is a data object consisting of two slots, each refering to some Lisp object. One slot is car (which stores the object in this cons cell), the other is cdr refers to nil, or another cons cell in the context of lists. A list is a series of cons cells chained together.

Proper lists
Proper lists refer to the lists whose last cons cell’s cdr is nil.
Dotted lists
Dotted lists refer to the lists whose last cons cell’s cdr is not nil.
Circular lists
… whose last cons cell’s cdr point to one of the previous cons cell in the list.

1. Predicates on Lists

consp obj
Checks if the object is cons cell.
atom obj
Opposite of consp, equivalent to (not (consp obj))
listp obj
Checks if is a cons cell or nil.
null obj
Checks if is nil.
proper-list-p obj
Check if is a proper list.

2. Accessing Elements of Lists

car cons-cell
Return the value of car of cons cell. Or the first element in the list.
cdr cons-cell
Return the cdr of cons cell. Or the list except the first element.
pop list
Removes and returns the first element of the list. It modifies the list.
nth n list
Returns the n-th element of the list (0-indexed). Returns nil if exceeds list length.
nthcdr n list
Discards the first n elements and returns the rest of the list.
take n list
Takes the first n elements of the list. Does not modify the list.
ntake n list
Same as take but modifies the list.

Date: 2026-08-11 Tue

Author: ArcaLunar