My 1.5cents
My 1.5cents
I don't mean that I don't understand it. I even know they come from assembler instruction names. And they still look weird to me and still have no meaning despite having read what the abbreviation expands to three or four times.
You'd be far better off shipping "first" & "rest" and whispering to the old hands that you're sure they know how to "fix" the problem in their code, than presenting new people with car & cdr and then try to wedge an explanation into a brain that just threw an exception and went "Wait, what?"
I like the distinction of car/cdr meaning pointers vs first/rest meaning "start of list/rest of list".
It weirded me out at first, but I came to really appreciate it.
(def x ((((5 4 3 2 1) 6) 7) 8 9))
(get-in x (0 0 0 1))
Probably botched quoting, don't know common lisp, only clojure.Some examples (from Haskell):
>>> ((((5,4,3,2,1),6),7),8,9) & view (_1 . _1 . _2)
6
>>> ((((5,4,3,2,1),6),7),8,9) & (_1 . _1 . _2) .~ 4
((((5,4,3,2,1),4),7),8,9)
>>> let foo = ((((5,4,3,2,1),6),7),8,9)
>>> foo & view (_1 . _1 . _2)
6
>>> let six = _1 . _1 . _2
>>> foo & view six
6
>>> foo & six .~ 4
((((5,4,3,2,1),4),7),8,9)
>>> foo & six .~ "abc"
((((5,4,3,2,1),"abc"),7),8,9) (let ((x '((((5 4 3 2 1) 6) 7) 8 9)))
(syntax->datum
(syntax-case x ()
((((_ p) _) _ ...) #'p)))) - both 3 letters each
- only differ by 1 letter a|d
None of the alternatives have these symmetry, and it (very subjectively) shows in the code.While writing a toy lisp I looked for other names with structural qualities, actually not names, more symbols since these weren't words.
Things like Oo/oO, xo/ox or _/__.
car and cdr are mnemonics related to the particular instruction set of the first computer on which Lisp happened to be implemented, which is great for people with a background with system programming on that system, but not so good for anyone else.
They're entrenched enough in the language that they are worth changing unless you are intentionally building a new Lisp-like language from scratch with some other main motivation and the change is just a side issue -- and it is clear that having something that doesn't imply list semantics for cons cells like first/rest does is good -- but car/cdr aren't a particularly good pair.
If I tried to explain deeper, Lisp focus on recursion over cons-lists was so foreign to the mainstream paradigms, that car/cdr, as most used operations, became symbolic axioms in my mind.
[1] which goes all in on the intuitive, human, pragmatic side of things, throwing away some old lisp idioms.
As funny as it is, people whining about "car/cdr" and saying "language X did it better because it called them first/last, or head/tail" don't realize that it's the language X that lacks semantics to express anything else than lists using cons cells.