Re:The Origin of CAR and CDR in Lisp (2005)
by kazinator on Tuesday December 26, 2017 @07:43PM
(#16012025)
TXR Lisp, a dialect with true conses:
1> (car "abc")
#\a
2> (cdr "abc")
"bc"
3> (cddr "abc")
"c"
4> (cdddr "abc")
nil
5> (caddr "abc")
#\c
Re:The Origin of CAR and CDR in Lisp (2005)
by lvh on Wednesday December 27, 2017 @10:27AM
(#16015252)
I'm not sure if that's what you meant, but the point I was addressing was that "first" is bad because you could reasonably expect it to work on anything sequentialish not just on conses (agreed), and car/cdr is explicitly about conses (agreed). But first, in some Lisps, works just fine on everything sequentialish, including vectors and strings, so I don't consider that a particularly strong argument.
cl, cr I could live with, maybe. (consleft, consright). Other suggestions, head and tail, fst and snd, which have some of the other touted advantages. (I don't necessarily agree with them, but they also don't hurt, so...)
Re:The Origin of CAR and CDR in Lisp (2005)
by kazinator on Saturday December 30, 2017 @01:07AM
(#16034090)
car and cdr is not necessarily about conses. I made them the basis for iterating over any list-like sequences in TXR Lisp. To participate in the protocol, an object can implement methods called cdr, car and nullify. This latter nullify should return nil if the object considers itself as representing "empty". Otherwise it can return the object itself, or possibly something else, like an ordinary list.
That may be true in LISP, but it's not true in Clojure (which I assume is a fair paragon for the first/rest camp), where first works just fine on strings and vectors:
> 5. When you're operating on lists as trees, the names first and rest are actively misleading. The car and cdr are the left and right subtrees, not the first and rest of something.Firstly, trees can clearly branch out more than n=2. Then, nth becomes a much cleaner term than "left" and "right" which immediately limit you to 2 cases. But, let's say we're talking about n=2 trees. Consider:
And, of course, if that still seems unreasonable: ... but maybe what you really want is a zipper, which has everything you're asking for and more: https://clojure.github.io/clojure/clojure.zip-api.html#cloju...