Right after parentheses, one of the things about Lisp that non-Lispers—and even some Lispers—like to complain about are the names of the two functions car
and cdr
. A common understanding is that car
returns the first entry of a list and cdr
returns everything after the first entry but they’re more accurately thought of as returning the contents pointed at by the first and second halves of a cons cell. That view helps us understand where the names come from.
The names are an historical artifact from the first implementation of Lisp and refer to a pair of assembly language macros used to access the two halves of the IBM 704 CPU registers. When a cons cell was in a register, the car
macro would access the first half of the cell and the cdr
macro would access the second half. Some Lispers have sought to replace these, admittedly opaque, names with something more intuitive and obvious such as head
and tail
or first
and rest
. Many have resisted these efforts, finding car
and cdr
short and perfectly adequate. Paul Graham makes a cogent argument for the traditionalists’ view:
(a) More mnemonic names tend to be over-specific (not all cdrs are tails), and (b) after a week of using Lisp, car and cdr mean the two halves of a cons cell, and languages should be designed for people who’ve used them for more than a week.
— Paul Graham (@paulg) October 15, 2019
I learned Lisp by reading Graham’s books so my thinking on Lisp matters is often informed by his but that aside, I agree with his tweet completely. It makes a convincing case for using car
and cdr
.
This discussion applies to Elisp too, of course, so Emacsers asking how they can alias car and cdr to head and tail should consider Graham’s argument carefully.