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
.
Copyright © 2007-2012 Janet Davis, Matthew Kluber, Samuel A. Rebelsky, and Jerod Weinman. (Selected materials copyright by John David Stone and Henry Walker and used by permission.)
This material is based upon work partially supported by the National Science Foundation under Grant No. CCLI-0633090. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the National Science Foundation.
This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 License .