Constructing List Structure

The basic function that constructs new list structure is the function cons.

If y is a list, then we can think of (cons x y ) as adding the new element x to the front of the list y.

(cons 'a '(b))      =  (a b)

(cons 'a '()) = (a)

(cons '(a) '(b)) = ((a) b)

(cons 'a 'b) = (a . b)

The following axioms always hold:

  1. (car (cons x y )) = x

  2. (cdr (cons x y )) = y

Lisp guarantees that every pair made by cons is brand-new and distinct from any other pair.

Contents    Page-10    Prev    Next    Page+10    Index