Copyright (C) 2000-2012 |
GNU Info (librep.info)Cons CellsCons Cells ---------- A "cons cell" is an ordered pair of two objects, the "car" and the "cdr". The read syntax of a cons cell is an opening parenthesis followed by the read syntax of the car, a dot, the read syntax of the cdr and a closing parenthesis. For example a cons cell with a car of 10 and a cdr of the string `foo' would be written as, (10 . "foo") - Function: cons car cdr This function creates a new cons cell. It will have a car of CAR and a cdr of CDR. (cons 10 "foo") => (10 . "foo") - Function: consp object This function returns true if OBJECT is a cons cell. (consp '(1 . 2)) => t (consp '()) => () (consp (cons 1 2)) => t The strange syntax `'(1 . 2)' is known as "quoting" (Note: Quoting), it tells the evaluator that the object following the quote-mark is a constant, and therefore should not be evaluated. This will be explained in more detail later. In Lisp an "atom" is any object which is not a cons cell (and is, therefore, atomic). - Function: atom object Returns true if OBJECT is an atom (not a cons cell). Given a cons cell there are a number of operations which can be performed on it. - Function: car cons-cell This function returns the object which is the car (first element) of the cons cell CONS-CELL. (car (cons 1 2)) => 1 (car '(1 . 2)) => 1 - Function: cdr cons-cell This function returns the cdr (second element) of the cons cell CONS-CELL. (cdr (cons 1 2)) => 2 (cdr '(1 . 2)) => 2 - Function: rplaca cons-cell new-car This function sets the value of the car (first element) in the cons cell CONS-CELL to NEW-CAR. The value returned is CONS-CELL. (setq x (cons 1 2)) => (1 . 2) (rplaca x 3) => (3 . 2) x => (3 . 2) - Function: rplacd cons-cell new-cdr This function is similar to `rplacd' except that the cdr slot (second element) of CONS-CELL is modified. automatically generated by info2www version 1.2.2.9 |