Believe it or not, but every list operation (more or less) can be defined in terms of these five basic operations.
null
(cons
value
lst
)
value
to the front of lst
.
(cdr
lst
)
lst
but without
the first element. (car
lst
)
lst
.
(null?
lst
)
lst
is the empty list.
(list
val_0
val_1
...
val_n
)
n
+1 of the form
(val_0
val_1
... val_n
)
.
(make-list
n
val
)
n
copies of val
.
(list-drop
lst
n
)
n
elements of lst
.
(list-take
lst
n
)
n
elements of lst
.
(for-each
proc!
lst
)
proc!
to each element of the
given list. Called primarily for side effects.
(map
func
lst
)
func
to the corresponding element of
lst
.
Most of these are forthcoming.
(list-ref
lst
n
)
n
th element of
lst
. Note that elements are numbered
starting at 0.
(reverse
lst
)
lst
, but in the opposite order.
car
and cdr
(caar
lst
)
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.
(cadr
lst
)
lst
,
the car
of the cdr
of lst
(cddr
lst
)
lst
,
the cdr
of the cdr
of lst
(caddr
lst
)
lst
,
the car
of the cdr
of the cdr
of lst
.