This is a basic
operation in the
LISP programming language (also LISP-derivative languages, such as
Scheme) used to access the first element in a
list.
Sample Usage:
- Returns the first element in a simple list
(CAR '(A B C D))
>A
- Returns the first list in a compound list
(CAR '((YELLOW DOG) (RED HAT) (RED FLAG) LINUX ROCKS))
>(YELLOW DOG)
- (Returns the first list of lists in a compound list)
(CAR '(((BUFFALO BUFFALO) (BUFFALO(BUFFALO BUFFALO))) BUFFALO))
>((BUFFALO BUFFALO) (BUFFALO (BUFFALO BUFFALO)))
Origin of the term (from the Jargon File): The instruction format of the IBM 704 that hosted the original LISP implementation featured two 15-bit fields called the `address' and `decrement' parts. The term `cdr' was originally `Contents of Decrement part of Register'. Similarly, `car' stood for `Contents of Address part of Register'.