Lists

The Basics

Believe it or not, but every list operation (more or less) can be defined in terms of these five basic operations.

null
Standard list constant. The empty list.
(cons value lst)
Standard List Procedure. Create a new list by prepending value to the front of lst.
(cdr lst)
Standard List Procedure. Get a list the same as lst but without the first element.
(car lst)
Standard List Procedure. Get the first element of lst.
(null? lst)
Standard list predicate. Checks if lst is the empty list.

Making Lists and Sublists

(list val_0 val_1 ... val_n)
Standard List Procedure. Create a new list of size n+1 of the form (val_0 val_1 ... val_n).
(make-list n val)
Customary List Procedure. Make a new list that consists of n copies of val.
(list-drop lst n)
List Procedure. Build a new list that consists of all but the first n elements of lst.
(list-take lst n)
List Procedure. Build a new list that consists of the first n elements of lst.

List Iteration Procedures

(for-each proc! lst)
Standard Higher-Order List Procedure. Apply proc! to each element of the given list. Called primarily for side effects.
(map func lst)
Standard Higher-Order List Procedure. Create a new list, each of whose elements is computed by applying func to the corresponding element of lst.

Most of these are forthcoming.

(list-ref lst n)
Standard List Procedure. Get the nth element of lst. Note that elements are numbered starting at 0.
(reverse lst)
Standard List Procedure. Build a new list whose elements are the same as those of lst, but in the opposite order.

Hybrids of car and cdr

(caar lst)
Standard List Procedure. If lst's first element is a list, gets the first element of that first element, the the car of the car of lst. If lst is not a list, or its first element is not a list, reports an error.