5 ms·
I think people might still start new s-expression based languages, whereas any respectable new language will use head/tail rather than car/cdr.
by lmm 10y ago
I think people might still start new s-expression based languages, whereas any respectable new language will use head/tail rather than car/cdr.
- Turing_Machine 10y agoFirst and rest make more sense if you're only going one level down, true. Long-term Lisp fans will argue that the composability shorthand of caddar, cddddr, cadadar, etc. is just too useful to give up.
- aninhumer 10y agoI think needing to use such operators is already indicative of inadequate tools to express structure. And if I did need to use something as complex as `cadadar` frequently for some reason, I'd much rather give it a name (and a type) that expresses what I'm actually doing with it.
- Turing_Machine 10y agoWell, the point is not that you use cadadar all the time as such, but that you also use cdddar, caadr, and so on, and that having these shorthand forms available means that you don't have to define a whole bunch of one-off functions.
- aninhumer 10y agoI think saying you can use `cadadar` to operate on a data structure instead of defining an accessor is like saying you can use pointer arithmetic to work with data structures in C instead of using structs. EDIT: And as other people have mentioned, most serious lisps already have proper tools for building data-structures, so I'm inclined to think that if you're using `cadadar` you're probably doing something wrong.
- Turing_Machine 10y ago"I'm inclined to think that if you're using `cadadar` you're probably doing something wrong." That's nice. I'm inclined to think that you haven't written very much Lisp code.
- dang 10y agoI don't know about respectable, but I prefer car/cdr even in a new Lisp. In addition to the composability of the notation, which others have cited, there's the clear lexical symmetry between the two; their compactness, which adds value when writing and reading concise programs; and how easy they are to say out loud. There's something also about their precision: when you say 'car' or 'cdr' in a Lisp context it's immediately clear that there's a linked list at hand and you're talking about it. The main disadvantage is that they're words with no immediate connection to their meaning, but that's true of many words we're all familiar with. It really only costs anything in the learning stage—which admittedly is a critically important stage. But I think it's fair for a programming language to use specialized idioms for a small number of their most fundamental constructs.
- bluefox 10y agoCAR and CDR are also good names because they are part of the Lisp tradition. Also due to this tradition, they have a clear meaning in the context of Lisp. If the "new Lisp" keeps conses (and some may argue that if it doesn't, it shouldn't really fall under "a Lisp"...), perhaps it should also keep these names.
- kbp 10y agoConses are arbitrary pairs, not necessarily lists. car and cdr are what eg OCaml and Haskell call fst and snd.