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.
[ Parent
| on HN ]
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.html