cons function constructs lists; it is the inverse of
cdr. For example,
cons can be used to make
a four element list from the three element list,
(fir oak maple):
(cons 'pine '(fir oak maple))
After evaluating this list, you will see
(pine fir oak maple)
appear in the echo area.
cons causes the creation of a new
list in which the element is followed by the elements of the original
We often say that ‘
cons puts a new element at the beginning of
a list; it attaches or pushes elements onto the list’, but this
phrasing can be misleading, since
cons does not change an
existing list, but creates a new one.
cons is non-destructive.
|• Build a list:|
|• length:||How to find the length of a list.|