Contents    Page-10    Prev    Next    Page+10    Index   

Access to Parts of a List

The two fields of a cons cell are called first, the first item in the list, and rest, the rest of the list after the first element.[In the original Lisp, first was called car, and rest was called cdr.]


(first '(a b c))                ->  a

(rest '(a b c))                 ->  (b c)

(first (rest '(a b c)))         ->  b
(second '(a b c))               ->  b

(first (rest (rest '(a b c))))  ->  c

(defn third [x] (first (rest (rest x))))
(third '(a b c))                ->  c

(rest (rest (rest '(a b c))))   ->  ()