On Jun 28, 12:41 am, "Stephen C. Gilardi" <squee...@mac.com> wrote:
> On Jun 28, 2009, at 12:07 AM, Handkea fumosa wrote:
>
> > user=> (list? '(1 2 3))
> > true
> > user=> (list? (cons 4 '(1 2 3)))
> > false
>
>    user=> (doc cons)
>    -------------------------
>    clojure.core/cons
>    ([x seq])
>      Returns a new seq where x is the first element and seq is
>        the rest.
>    nil
>    user=> (cons 4 '(1 2 3))
>    (4 1 2 3)
>    user=> (seq? (cons 4 '(1 2 3)))
>    true
>    user=> (first (cons 4 '(1 2 3)))
>    4
>    user=> (rest (cons 4 '(1 2 3)))
>    (1 2 3)
>    user=> (list? (rest (cons 4 '(1 2 3))))
>    true
>    user=>
>
> cons is acting according to its documentation.

It's list? that isn't.

> Some of the roles played by lists in other Lisps are played by seqs in  
> Clojure. Also, in Clojure a list is not a linked list of cons cells.  
> Roughly speaking, a Clojure list is a linked list of lists:
>
>    user=> (list? (rest (rest (rest '(1 2 3 4 5 6 7)))))
>    true

My current workaround is to use

(defn fixed-list? [obj]
  (and (sequential? obj) (not (vector? obj))))

This gives me the desired semantics: it's a list if it's a ()
collection rather than a [], {}, or #{} collection.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to