On Jun 24, 2011, at 7:35 PM, Tim Robinson wrote: > I'm under the impression that traditional lisps have a greater > distinction between a cons operation vs. a list operation. > Specifically I had believed that consing was a more efficient and > better performing operation than using list. >
This is not true, but it is also not relevant. In historical Lisps, the list datatype is a singly-linked list consisting of nodes known as CONS cells. In Common Lisp, for example, the predicate (listp obj) is simply equivalent to the test (typep obj '(or cons null)). A list is either a (chain of) CONS or the empty list. Notice that this implicitly includes "improper" lists (dotted pairs) such as (cons 1 2). In Clojure, on the other hand, it is illegal for the second argument to 'cons' to be an atom: (cons 1 2) => java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Integer A Lisp form such as (list 1 2 3) is just a series of calls to cons: (cons 1 (cons 2 (cons 3 '()))). > Is this true? and if so, given both the Cons and Lists are actually > both just seqs in Clojure, does the above statement still hold true in > the Clojure world? > As I mentioned, the correspondence between LIST and CONS in traditional Lisps is not really relevant in Clojure, where the emphasis is on the sequence abstraction. A sequence simply satisfies an interface that provides a 'first' element, the 'rest' of the sequence, and allows you to construct ('cons') a new sequence from an existing one. Lists and vectors are two concrete sequence types, and they have significant differences in terms of behavior and performance. But in Clojure you can 'cons' using a list or a vector. So the rules are a little different from other Lisps. Have all good days, David Sletten -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en