News for hackers. Stuff that matters.
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