On Feb 14, 2009, at 4:47 PM, wubbie wrote:

Hi,
Why vector is not a seq?

user=> (seq? [1 2 3])
false
user=> (seq? '(1 2 3))
true

Most sequence functions automatically arrange to call "seq" on their arguments, so it's easy to start thinking that Clojure collections *are* seqs. In the general case, they are not. They are, however, seq- able meaning that if you call seq on them you will get a seq: a view on their contents that implements the seq interface.

        user=> (seq? (seq [1 2 3]))
        true
        user=> (seq? (seq '(1 2 3)))
        true

List implements seq directly, so when you call seq on it, seq returns the list itself. Vector does not implement seq directly (because that wouldn't be efficient), so when you call seq on it you get a new object.

        user=> (def l '(1 2 3))
        #'user/l
        user=> (identical? l (seq l))
        true
        user=> (def v [1 2 3])
        #'user/v
        user=> (identical? v (seq v))
        false

--Steve

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to