Re:CAR and CDR
by csmuk on Wednesday November 20, 2013 @04:44AM
(#6767127)
Still prefer first and rest. At least that has meaning outside the first use of car and cdr.
[ Parent
| on HN ]
I can't disagree with that, but after learning clojure I realized that I interned `car` and `cdr` as symbols of which I like :
- the symmetry: 'c[ad]r'
- thus same size
- small size (3)
and ended up being annoyed by `first` and `rest`. I see them as APL-like characters now.ps: based on that, head/tail, hd/tl, fst/snd (seen in ml dialects) are also good candidates.
I'll take head/tail over first/rest, but first/rest is not too bad.
I thought that for a bit until I realised tail is a bit ambiguous as it's used in the Unix space to mean the "last n" items and in some data structures as the last item pointer.
Re:CAR and CDR
by mrottenkolber on Wednesday November 20, 2013 @05:02AM
(#6767188)
Ironically in CL LAST does what UNIX tail does.
Yeah which is where SBCL and me got into to a bad argument :)
Re:CAR and CDR
by mrottenkolber on Wednesday November 20, 2013 @05:10AM
(#6767209)
You probably were looking for LAST1 (e.g. (first (last ...))).
But why SBCL? LAST should behave the same on all implementations.
That's just the variety of CL that I used.
I'm a fan first/rest because of Mathematica. It has four functions that all end in "st", which means I can always recall the one I need:
First, Rest, Most, Last
(Results on Range[4], respectively: 1, {2, 3, 4}, {1, 2, 3}, 4.)
Rebol comes with first & last but not the others.
>> a: [1 2 3 4]
== [1 2 3 4]
>> first a
== 1
>> last a
== 4
This is how you could add rest & most: >> rest: func [s] [next s]
>> most: func [s] [copy/part s back tail s]
>> rest a
== [2 3 4]
>> most a
== [1 2 3]
Rebol unifies all this under what it calls a series - http://www.rebol.com/docs/core23/rebolcore-6.htmlIn Clojure it's almost the same: first, rest, butlast, last
Re:CAR and CDR
by mrottenkolber on Wednesday November 20, 2013 @04:54AM
(#6767162)
It has nothing to do with preference. FIRST and REST are to be used when working on a LIST, CAR and CDR when working on CONS cells.
Yes but every structure that a cons represents can be expressed in terms of first and rest. That includes tables, singly linked lists, doubly linked lists, binary trees from experience.
Car and Cdr are arbitrary and legacy terms.
Re:CAR and CDR
by mrottenkolber on Wednesday November 20, 2013 @05:07AM
(#6767199)
Arbitrary and legacy, sure, but they do serve their purpose by communicating different expectations when using a single operator. CDR? result can be anything. REST? author probably thinks the result will always be a LIST. I can think of other examples using SETF but I think I made my point clear.
Same here, but cons cells can be used to model things other than lists, where semantically first and rest don't make sense.
Re:CAR and CDR
by thaumasiotes on Wednesday November 20, 2013 @06:17AM
(#6767389)
I once wrote an in-place quicksort in common lisp where I kept pointers to locations of interest in the list as halves of a cons cell. Was kind of fun coming across it later and figuring out what it did. That cons cell made no semantic sense as a linked list; it was just a pair of pointers.
Re:CAR and CDR
by outworlder on Wednesday November 20, 2013 @07:35AM
(#6767622)
They are better, until you try to compose them :)
but saying "cudder" is so much more fun
Yes but macros like caaaaaar and caaadr aren't :)
I'd rather salt my eyeballs.