News for hackers. Stuff that matters.
Re:The Origin of CAR and CDR in Lisp (2005) by CalChris on Tuesday December 26, 2017 @11:05AM (#16009150)
The LISP people should have changed those names way back when. Not 79, 59. McCarthy himself said then that this representation is independent of the IBM 704 computer, or of any other electronic computer [1]. So why stick with the names of 704 registers? Was there a purpose to this?

[1] https://courses.engr.illinois.edu/cs421/sp2012/project/mccar...

Re:The Origin of CAR and CDR in Lisp (2005) by lispm on Tuesday December 26, 2017 @11:13AM (#16009188)
Lisp has both CAR/CDR and FIRST/REST.

It's usual programming style to use CAR/CDR when working with CONS trees/graphs and FIRST/REST when working with lists.

Re:The Origin of CAR and CDR in Lisp (2005) by AnimalMuppet on Tuesday December 26, 2017 @01:32PM (#16010045)
OK, but isn't CalChris's point still valid? Something other than CAR/CDR would have been a better choice for working with CONS cells, even back in 1959.

Do I think it's a big problem? Not really. Are the names less than optimal? Yes.

Re:The Origin of CAR and CDR in Lisp (2005) by kazinator on Tuesday December 26, 2017 @01:56PM (#16010211)
These names were very well thought out. They were part of a larger vocabulary in fact; most of that vocabulary died out and only car and cdr remained. There were things like cwr, ctr and others. MacCarthy and gang were well aware (of all people!) that the language is machine-independent and not something that will be forever stuck to the particular IBM machine; they used these names anyway because there was nothing wrong with them.

By the way, the C and R are not machine specific; any machine can have a "register" and any register can have "contents". On any machine where we implement cons cells, we can just call the two fields registers, understood as being A and D.

These, in turn, can be "ante" and "de", if someone desperately needs mnemonics:

https://en.wiktionary.org/wiki/ante

https://www.etymonline.com/word/de-

"active word-forming element in English and in many words inherited from French and Latin, from Latin de "down, down from, from, off; concerning."

Re:The Origin of CAR and CDR in Lisp (2005) by DonaldFisk on Tuesday December 26, 2017 @06:03PM (#16011623)
In addition to car and cdr, there were cpr (Contents of the Prefix part of Register) and ctr (Contents of the Tag part of Register).

> By the way, the C and R are not machine specific; any machine can have a "register"

Slight nitpick: the first machine on which I had a decent Lisp to use (Portable Standard Lisp) was a Burroughs 6800, a stack machine with no general purpose registers, or indeed any registers directly accessible by the programmer.

Re:The Origin of CAR and CDR in Lisp (2005) by kazinator on Wednesday December 27, 2017 @03:30AM (#16013616)
Vi has "registers" and so do TeX and troff. I think once upon a time, it was more common to use the word for things beside CPU registers and I/O ports.

If a cons cell is a context with two registers (R) whose contents we can access (C), the only vestiges of that IBM machine are the A and D letters sandwiched in between to distinguish them.

Compared to how option letters change meaning between Unix commands, it's nothing. -h help? Nope, h)uman readable sizes.

^ to anchor regex at beginning; $ for end. Because on common keyboards, ^ is on the right, and $ on the left!

Re:The Origin of CAR and CDR in Lisp (2005) by kbp on Tuesday December 26, 2017 @01:46PM (#16010145)
> Something other than CAR/CDR would have been a better choice for working with CONS cells, even back in 1959.

> Are the names less than optimal? Yes.

I don't think that's self-evident. The only better alternatives I've ever heard suggested are something like left and right, which I think are probably slightly clearer names for what the functions do, but not significantly so (I don't think "a cons is a thing with a left and right side" is that much more intuitive than "a cons is a thing with two parts called a car and a cdr").

Further, I think in 1959 when most everyone using Lisp was hacking on the implementation itself, names that are mnemonic for what the machine they were actually using is actually doing make sense; I don't think they're clearly sub-optimal now, but I think they were even less so in 1959.

Re:The Origin of CAR and CDR in Lisp (2005) by AnimalMuppet on Tuesday December 26, 2017 @02:18PM (#16010334)
I assert that naming the interface for the implementation is almost always the wrong thing to do.

(And then you ask me what would be a better name, and I don't have a perfect answer. "left" and "right" are the best I know of...)

Re:The Origin of CAR and CDR in Lisp (2005) by kbp on Tuesday December 26, 2017 @02:30PM (#16010427)
> I assert that naming the interface for the implementation is almost always the wrong thing to do.

I think it's perfectly acceptable if there aren't really any better names for the abstraction you're creating. car and cdr work just fine as made-up arbitrary names for an abstraction that doesn't really have any more natural names for them; the fact that 60 years ago they weren't actually entirely arbitrary doesn't really change that.

Re:The Origin of CAR and CDR in Lisp (2005) by kbp on Tuesday December 26, 2017 @11:14AM (#16009196)
> So why stick with the names of 704 registers? Was there a purpose to this?

Are there other, much better names for the two parts of a pair? First and second aren't great because they're not clear that it's a pair and not a larger sequence (and the difference is important in Lisp; since lists are built on conses, it would be odd to get the tail of a list by calling 'second'). The only other names I can think of would be something like left and right, but I don't think those would be substantially easier to understand for beginners than car and cdr.

When working with lists, many people prefer to use the functions first and rest, which behave identically to car and cdr but are more meaningfully named for list applications. They would be terrible names for the general cons-handling functions, though.

Re:The Origin of CAR and CDR in Lisp (2005) by currymj on Tuesday December 26, 2017 @11:43AM (#16009341)
Left and Right are really commonly used in this situation in ML-descended languages. It’s not the worst thing.

I don’t mind car and cdr though. I kind of wish they were in Clojure tbh. It feels nice to pay tribute to a half-century of computing history.

Re:The Origin of CAR and CDR in Lisp (2005) by kbp on Tuesday December 26, 2017 @11:53AM (#16009388)
> Left and Right are really commonly used in this situation in ML-descended languages. It’s not the worst thing.

Are you talking about Either types? OCaml and Haskell at least both call car and cdr fst and snd respectively, but they're rarely used.

As for left and right as names, I don't think they're any worse than car and cdr, I just don't think they're substantially better.

Re:The Origin of CAR and CDR in Lisp (2005) by Steltek on Tuesday December 26, 2017 @11:35AM (#16009308)
Would it be silly to use 'head' and 'tail' then?

I learned car/cdr in school so that's what I use.

Re:The Origin of CAR and CDR in Lisp (2005) by lisper on Tuesday December 26, 2017 @11:31AM (#16009276)
I use FST and RST (for FIRST and REST). I like them because they are short, mnemonic, and can be composed like CAR and CDR, e.g. CADADDR = FRFRRST (though I also believe that if you find yourself doing this you're almost certainly doing something wrong).
Re:The Origin of CAR and CDR in Lisp (2005) by CJefferson on Tuesday December 26, 2017 @02:41PM (#16010494)
In C++, I often use LHS and RHS (left hand side / right hand side). I know other people who like fst, eat (first, rest). Both seem better to me, as they have some meaning other than random made up strings (for people who don't use 704).
Re:The Origin of CAR and CDR in Lisp (2005) by kbp on Tuesday December 26, 2017 @03:14PM (#16010706)
> Both seem better to me, as they have some meaning other than random made up strings (for people who don't use 704).

Calling the lefthand child of a node in a binary tree the "first" and the righthand child the "rest" seems like a markedly worse naming system than random made-up names, to me, because the use of English names seems to be implying meaning that it doesn't really offer.

The idea of a thing with two values, one on the left side and one on the right side is probably a bit more intuitive, but I really doubt it's that much moreso than just saying it has two parts called the car and the cdr. People who've never touched a 704 have been learning about conses as a data structure with two parts, a car and a cdr, for almost 60 years; to most of them, it's just vocabulary you learn now, the same way that numerator and denominator are just arbitrary names to people learning fractions.

I also think it's interesting how much people complain about car and cdr yet it's very rare that people complain about cons, which is just as badly named. It should probably have been called make-pair or something, which I think is a much bigger improvement than car vs lhs. But really, it's 3 words of vocabulary, whose definitions can be completely understood by

    (car (cons x y)) = x
    (cdr (cons x y)) = y
That's not very much to ask someone to wrap their head around, it was meaningful to the original implementors, and for people now there's about 60 years of precedent for using that terminology.
Re:The Origin of CAR and CDR in Lisp (2005) by CJefferson on Tuesday December 26, 2017 @03:29PM (#16010805)
I feel the better question, and I don't know the answer, is does this kind of thing stop people taking up lisp. Honestly I think it does, for so many languages, the first view, the first 15 minutes of reading, and the first 10 hours are super important, that is when you lose many possible users. It is certainly the points where I often drop languages.

While lisp is old, it's never picked up many users. This is the kind of little thing which makes me not want to teach it (not just this, but just lots of little ways it seems stuck in history).

Re:The Origin of CAR and CDR in Lisp (2005) by kbp on Tuesday December 26, 2017 @03:41PM (#16010885)
I think that's more attributable to the fact that for most people, their first 10 hours with Lisp are spent writing recursive functions that explicitly cdr down lists, rather than the names car and cdr. I think it would make a much bigger difference if more people's first exposure to Lisp was something like:

    (with-open-file (input "foo.txt")
      (loop for line = (read-line input nil)
            while line
            do (write-line line)))
But instead most schools only use Lisp as a vehicle for teaching the basics of recursion and functional programming, rather than as an immediately useful tool, so most students go away with the idea that that's what Lisp is used for, and attribute their difficulty understanding The Little Schemer to difficulty understanding Lisp.
Re:The Origin of CAR and CDR in Lisp (2005) by flavio81 on Tuesday December 26, 2017 @10:11PM (#16012564)
>But instead most schools only use Lisp as a vehicle for teaching the basics of recursion and functional programming, rather than as an immediately useful tool, so most students go away

This was my experience too. In university, Lisp seemed like an awkward, limited language for doing some CS algorithms. So i totally overlooked it.

Fast forward 12 years later, reading in depth about Common Lisp and using it as a general purpose programming language, it's totally awesome.

Re:The Origin of CAR and CDR in Lisp (2005) by kazinator on Wednesday December 27, 2017 @02:45AM (#16013469)
Wanting to optimize my path through school, I asked some senior people if that programming languages course based on Scheme was useful. I was informed that it's a toy language based on Lisp for teaching. I correctly assumed that this is something other than the real Lisp, a legendary language which can't be a toy. It being a university for grown up children and all, I didn't want to have anything to do with toys. The course was a prerequisite for a senior level compiler course, but I talked the prof into letting me skip the prerequisite and go straight to that compiler course.

Man, I sure dodged a bullet there. Some decade later, I got into Lisp in a big way (the real one); the rest is history.

Re:The Origin of CAR and CDR in Lisp (2005) by kazinator on Wednesday December 27, 2017 @03:14AM (#16013566)
Nothing that was based on garbage collection picked up a lot of users before 1999 or so.

Basically when the world "rebooted" into garbage collected, managed languages, it was amid a sort of Lisp amnesia. A lot of that was due to new people who had no such memory to recall.

Prior to this general movement, there were severe barriers in place against anything memory-managed.

And anyway, even if everyone who had already been programming in 1980 switched to Lisp today, it would be a drop in the bucket.

I think the original Lisp people didn't persevere enough. They peaked early. By the time Java and whatnot came around, the presence wasn't there.