car and cdr have had their fifteen minutes of fame
In response to
Six Things I Dislike About Ruby (and Four I Don't), someone quipped:
while we are stamping out those silly ungrammatical C++-isms like "puts", can we also get rid of those silly lispisms of 'car' and 'cdr'?
Yeah, sister (or brother, as the case may be)!
car and
cdr are historical anachronisms. They are like secret handshakes: their only remaining value is to help a small cadre of enthusiasts bond around a shared collection of obscure trivia.

I wouldn't be suprised if Lispers have droppped these from production systems in favour of the logo-isms
first and
rest. But then again, I wouldn't be surprised if some Lispers hang onto them either. After all, if every textbook uses them as examples, they become familiar through repetition, even if their names no longer make any sense whatsoever.
The last time I checked nobody was running Lisp on
IBM 704s any more. These names really deserve a quiet retirement in a shady home where they can share war stories with
puts while they listen to
goto complain about what happened when
call/cc made him obsolete.
All that being said, car and cdr were rather prolific parents: Lisp implementations usually support a special syntactic sugar called
composition where you can make up a function with the following form: (/c[ad][ad]*r/ ...) and this is executed as if you types a series of nested cars and cdrs. For example, (caddr foo) has the same effect as (car (cdr (cdr foo))).
I really like composition. We can sort of get that with dot notation and messages in languages like Ruby. But I secretly admire the way the German language lets you
compose entirely new nouns by sticking smaller nouns together.
I think car and cdr's composition has a spiritual descendant in Ruby's metaprogramming style. For example, dynamic finders in Rails.
Person.find_all_by_username_and_password really feels like caddaddr. Uh, maybe not.
But it's nice to see that some of the good ideas from Lisp thrive in new homes.
Labels: ruby