Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "my other car is a cdr" mean?

Tags:

lisp

cons

cdr

Can anyone well versed in lisp explain this joke to me? I've done some reading on functional programming languages and know that CAR/CDR mean Contents of Address/Decrement Register but I still don't really understand the humour.

like image 939
CaptainCasey Avatar asked Dec 08 '09 05:12

CaptainCasey


People also ask

What does CDR mean in cars?

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 ...

What are car and CDR used for?

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.

Why is it called CAR and CDR?

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.

What does cons mean in Scheme?

The primitive procedure cons means "construct." Cons takes two arguments and returns a list constructed from those two arguments. In this capacity, it provides a means of combination for the Scheme programming language. Note In programming languages, a constructor creates a new object, such as a list object.


3 Answers

In Lisp, a linked list element is called a CONS. It is a data structure with two elements, called the CAR and the CDR for historical reasons. (Some Common Lisp programmers prefer to refer to them using the FIRST and REST functions, while others like CAR and CDR because they fit well with the precomposed versions such as (CADR x) ≡ (CAR (CDR x)).

The joke is a parody of the bumper stickers you sometimes see on beat-up old cars saying "My other car is a Porsche/BMW/etc."

My response to this joke has always been "My other CAR is a CADR. CDR isn't a CAR at all."

like image 77
Peter S. Housel Avatar answered Oct 11 '22 14:10

Peter S. Housel


Yes, definitely a geek joke.

The names come from the IBM 704, but that's not the joke.

The joke is (bad) pun on "my other car is a ___." But the in-joke is about recursion.

When you loop/manipulate/select/invoke/more in lisp you use a combination of car (the first element in the list) and cdr (the rest of the list) to juggle functions.

So you've got a car, but your other car is your cdr because you can always get a car from a cdr since the cdr is always (in recursion) more elements. Get it? Laugh yet?

You'll probably have to learn lisp to actually chuckle a bit, or not. Of course, by then, you'll probably find yourself chuckling randomly for no apparent reason because:

Lisp makes you loopy.

like image 45
zen Avatar answered Oct 11 '22 13:10

zen


//Coming from Scheme
Scheme has very few data structures, one of them is a tuple: '(first . second). In this case, car is the first element, and cdr is the second. This construct can be extended to create lists, trees, and other structures.
The joke isn't very funny.

like image 14
Kobi Avatar answered Oct 11 '22 13:10

Kobi