News for hackers. Stuff that matters.
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.
Re:CAR and CDR by agumonkey on Wednesday November 20, 2013 @05:12AM (#6767213)
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.

Re:CAR and CDR by mercurial on Wednesday November 20, 2013 @04:48AM (#6767141)
I'll take head/tail over first/rest, but first/rest is not too bad.
Re:CAR and CDR by csmuk on Wednesday November 20, 2013 @04:54AM (#6767163)
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.
Re:CAR and CDR by csmuk on Wednesday November 20, 2013 @05:03AM (#6767191)
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.

Re:CAR and CDR by csmuk on Wednesday November 20, 2013 @05:25AM (#6767246)
That's just the variety of CL that I used.
Re:CAR and CDR by lgarron on Wednesday November 20, 2013 @05:30AM (#6767259)
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.)

Re:CAR and CDR by draegtun on Wednesday November 20, 2013 @07:32AM (#6767613)
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.html
Re:CAR and CDR by lcedp on Wednesday November 20, 2013 @07:06PM (#6772213)
In 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.
Re:CAR and CDR by csmuk on Wednesday November 20, 2013 @04:59AM (#6767179)
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.
Re:CAR and CDR by yati on Wednesday November 20, 2013 @05:41AM (#6767285)
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 :)
Re:CAR and CDR by xmonkee on Wednesday November 20, 2013 @04:59AM (#6767180)
but saying "cudder" is so much more fun
Re:CAR and CDR by csmuk on Wednesday November 20, 2013 @05:02AM (#6767190)
Yes but macros like caaaaaar and caaadr aren't :)

I'd rather salt my eyeballs.

Re:CAR and CDR by l0gicpath on Wednesday November 20, 2013 @05:08AM (#6767203)
Such a horror to see this in a large code base. s-expressions can get mentally taxing as it is, but then the abuse of continued acceptance is sad.