4 ms·
Still prefer first and rest. At least that has meaning outside the first use of car and cdr.
by csmuk 13y ago
Still prefer first and rest. At least that has meaning outside the first use of car and cdr.
- outworlder 13y agoThey are better, until you try to compose them :)
- mercurial 13y agoI'll take head/tail over first/rest, but first/rest is not too bad.
- csmuk 13y agoI 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.
- mrottenkolber 13y agoIronically in CL LAST does what UNIX tail does.
- csmuk 13y agoYeah which is where SBCL and me got into to a bad argument :)
- mrottenkolber 13y agoYou probably were looking for LAST1 (e.g. (first (last ...))). But why SBCL? LAST should behave the same on all implementations.
- csmuk 13y agoThat's just the variety of CL that I used.
- lgarron 13y agoI'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.)
- draegtun 13y agoRebol 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 http://www.rebol.com/docs/core23/rebolcore-6.html
- lcedp 13y agoIn Clojure it's almost the same: first, rest, butlast, last
- mrottenkolber 13y agoIt 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.
- csmuk 13y agoYes 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.
- mrottenkolber 13y agoArbitrary 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.
- xmonkee 13y agobut saying "cudder" is so much more fun
- agumonkey 13y agoI 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.
- deleted 13y ago[deleted]
- yati 13y agoSame here, but cons cells can be used to model things other than lists, where semantically first and rest don't make sense.
- thaumasiotes 13y agoI 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.