Building Lists Incrementally ...

Therefore, a list LST can be built up as follows:

  1. Initially, set LST to NIL or '() (a list of no elements).

  2. For each new element x, set LST to
    (CONS x LST) or use (PUSH x LST).

The following example illustrates `` CONSing up'' a list. Note that the element added last will be at the front of the list; REVERSE can be used to reverse the order if desired.


                                LST:
(SETQ LST '())                  NIL = ()

(SETQ LST (CONS 'A LST))        (A)

(SETQ LST (CONS 'B LST))        (B A)

(PUSH 'C LST)                   (C B A)

(SETQ LST (REVERSE LST))        (A B C)

Contents    Page-10    Prev    Next    Page+10    Index