Most of my Lisp experience comes from Elisp. As such, I find myself writing Lisp only on occasion. By the time I come back to it, I often forget the difference between car
and cdr
and need to reference the docs to jog my memory.
What kinds of clever mnemonics do you use to remember the difference between Lisp functions that have naming roots stemming from 1954 era computer architectures (car, cdr, cadr, caar, cddr, etc)?
In addition, why haven't the well-named aliases of first
and rest
gained more traction as idiomatic alternatives for car
and cdr
?
Update: I know the actual definitions of car
and cdr
and how they should be pronounced. Mnemonics only please.
Full Disclosure: This question isn't entirely for me. It's to help other Lisp newcomers get past some of the initial hurdles.
The popular explanation that CAR and CDR stand for "Contents of the Address Register" and "Contents of the Decrement Register" does not quite match the IBM 704 architecture; the IBM 704 does not have a programmer-accessible address register and the three address modification registers are called "index registers" by ...
The origins of the names for car and cdr are a little bit historical and comes from the IBM 704. car is an acronym from the phrase Contents of the Address part of the Register; and cdr is an acronym from the phrase Contents of the Decrement part of the Register.
The car and cdr functions are used for splitting lists and are considered fundamental to Lisp. Since they cannot split or gain access to the parts of an array, an array is considered an atom. Conversely, the other fundamental function, cons , can put together or construct a list, but not an array.
Of the two words car and cdr, car is the one I've heard first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With