Comment by lispm
8 years ago
> Clojure both Keeps and Breaks Tradition ... When Rich Hickey invented Clojure, he kept the gems of the LISP tradition, but jettison much of the muck. This is why Clojure has first instead of car and rest instead of cdr
Rich Hickey did not invent 'first' and 'rest'. LISP has those since the end of the 70s in language standards.
From Common Lisp the Language, published 1984, chapter on lists:
[Function]
first list
second list
third list
fourth list
fifth list
sixth list
seventh list
eighth list
ninth list
tenth list
These functions are sometimes convenient for
accessing particular elements of a list. first
is the same as car, second is the same as cadr,
third is the same as caddr, and so on.
Note that the ordinal numbering used here is
one-origin, as opposed to the zero-origin
numbering used by nth:
(fifth x) == (nth 4 x)
setf may be used with each of these functions
to store into the indicated position of a list.
[Function]
rest list
rest means the same as cdr but mnemonically
complements first. setf may be used with rest
to replace the cdr of a list with a new value.
Lisp Machine Lisp had FIRST, SECOND, ... REST1, ..., REST4 at least in 1979. They are documented in the 2nd edition Lisp Machine manual.
> > When Rich Hickey invented Clojure, he kept the gems of the LISP tradition, but jettison much of the muck. This is why Clojure has first instead of car and rest instead of cdr
> Rich Hickey did not invent 'first' and 'rest'.
Rather than the names 'car' and 'cdr', the "muck" that Rich Hickey jettisoned here was conses as a core language feature. Since Lisp already used first and rest for operating on lists, Clojure borrowed those names, and since Clojure doesn't have conses (in the Lisp sense of the term; Clojure has a cons function, but it just adds elements to sequences rather than constructing pairs), it didn't have any need for car and cdr, which operate on conses.
It reminds me of a section from Kent Pitman's article 'More Than Words, or: Lambda, the Ultimate Political Party':
> Some years ago, when I was first becoming involved with language standards, I did a personal study of languages in the Lisp family to determine whether there was a common core of operators that were present throughout the family with the same name and semantics.
Then after going through several basic operators which differ in behaviour or name across dialects, he concludes:
> I did find that CONS was present in every Lisp I looked at with pretty much the same meaning, but that seemed to be an isolated case
Paraphrasing Mr Adams - “The story so far: In the beginning LISP was created, .... and then Guy wrote the Common LISP Bible. This made a lot of people very angry and been widely regarded as a bad move.” - or, Common Lisp - the LISP communities attempt at a non-proliferation treaty with itself. :-)
Those who do not understand the history of Clojure are doomed to assert Rich Hickey invented Common Lisp.
> Rich Hickey did not invent 'first' and 'rest'.
No one claimed Hickey invented first and rest, or even implied it. The point is not that first and rest didn't exist, but that car and cdr DID. Clojure deliberately left them out, as a design choice. For good or ill, that's the point.
> No one claimed Hickey invented first and rest, or even implied it.
I think that saying "This is why Clojure has first instead of car and rest instead of cdr" is a very odd way of saying "this is why Clojure doesn't have car and cdr" if you don't mean to imply that it added first and rest.
I also think the originally linked article was rather poorly written and seemed to put all of the focus on "car and cdr sure are weird names" without examining that they are operations on cons cells, which Clojure doesn't have. Clojure leaving out the names car and cdr doesn't really have anything to do with those names; it left out the data structure they operate on. A language without numbers proably wouldn't have a sqrt function either, but that has little to do with the clarity of the name sqrt.
Discussing the differences and tradeoffs between how Lisps and Schemes all represent lists compared to how Clojure does (and the tradeoffs with how Clojure makes up for the other things that conses are used for in Lisp) might have made for a more interesting point, but it would have been a harder one to make than just pointing at two not immediately obvious symbol names (without even mentioning that it did keep the equally archaic and unhelpful name "cons" but changed its behaviour).
> but that car and cdr DID. Clojure deliberately left them out, as a design choice.
Clojure doesn't have the concept of Lisp's linked lists, thus it does not have its operators.
Note that where the link now points to is something different. Originally this was the link: http://www.howardism.org/Technical/Clojure/origin-of-car-and...
> Clojure deliberately left them out, as a design choice.
I don't think they were 'left out'. That's not how Clojure was designed, IIRC. Clojure is not first Lisp minus the arcane names, plus second then the new stuff. It's a new language from start, not Lisp with names left out. Hickey did not start with Lisp and redesigned it. He started with a new language, based on ideas like immutable persistent lazy sequences, host language integration with easy interoperation, some Lisp ideas like s-expressions and macros, ... I don't think he thought, 'I leave CAR and CDR out'. There was no place for them, since he designed the language Clojure around different data structure concepts.
Too bad we couldn't just have "nth" and call it a day.
We do have it, it is called "elt" in Lisp.
> We do have it, it is called "elt" in Lisp.
In Common Lisp, ELT is generic over sequences, so it also works on arrays. CL also has a function actually called NTH which is specific to lists; NTH was also in Maclisp, Lisp Machine Lisp, etc with the same meaning (Interlisp had an NTH function but it's what Common Lisp calls NTHCDR (except that Interlisp NTH used 1-based indexing whereas CL NTHCDR uses 0-based)). Emacs Lisp uses the same nth/elt distinction as Common Lisp. Islisp has elt which is generic over sequences, but I believe that it discarded nth.
No one said he invented them.