Car and Cdr versus Head and Tail

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:

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.

This entry was posted in General and tagged , , . Bookmark the permalink.