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.
-
(consvaluelst) - Standard List Procedure.
Create a new list by prepending
valueto the front oflst. -
(cdrlst) - Standard List Procedure.
Get a list the same as
lstbut without the first element. -
(carlst) - Standard List Procedure.
Get the first element of
lst. -
(null?lst) - Standard list predicate.
Checks if
lstis the empty list.
Making Lists and Sublists
-
(listval_0val_1...val_n) - Standard List Procedure. Create a
new list of size
n+1 of the form(.val_0val_1...val_n) -
(make-listnval) - Customary List Procedure.
Make a new list that consists of
ncopies ofval. -
(list-droplstn) - List Procedure.
Build a new list that consists of all but the first
nelements oflst. -
(list-takelstn) - List Procedure.
Build a new list that consists of the first
nelements oflst.
List Iteration Procedures
-
(for-eachproc!lst) - Standard Higher-Order List Procedure.
Apply
proc!to each element of the given list. Called primarily for side effects. -
(mapfunclst) - Standard Higher-Order List Procedure.
Create a new list, each of whose elements is computed by applying
functo the corresponding element oflst.
Additional List Procedures
Most of these are forthcoming.
-
(list-reflstn) - Standard List Procedure.
Get the
nth element oflst. Note that elements are numbered starting at 0. -
(reverselst) - Standard List Procedure.
Build a new list whose elements are the same as those of
lst, but in the opposite order. -
(member?vallst) - MediaScheme List Procedure.
Determine if
valappears inlst. If so, returns true (#t). If not, returns false (#f). -
(membervallst) - Standard List Procedure.
Determine if
valappears inlst. If so, returns the sublist that starts withval. If not, returns false (#f).
Hybrids of car and cdr
-
(caarlst) - Standard List Procedure.
If
lst's first element is a list, gets the first element of that first element, the thecarof thecaroflst. Iflstis not a list, or its first element is not a list, reports an error. -
(cadrlst) - Standard List Procedure.
Get the second element of
lst, thecarof thecdroflst -
(cddrlst) - Standard List Procedure.
Get all but the first two elements of
lst, thecdrof thecdroflst -
(caddrlst) - Standard List Procedure.
Get the third element of
lst, thecarof thecdrof thecdroflst.