> > > It is surprising at first, but since vectors are used so commonly in >> Clojure instead of lists to represent literal sequential collections of >> data, it turns out to be extremely convenient to be able to compare it for >> equality against sequential collections generated as lists or lazy >> sequences. Basically, all those things are just flat, linear collections, >> and what we really care about from an equality standpoint is whether the >> collections have the same elements in the same order. Clojure similarly >> considers different types of maps (hash-maps, array-maps, sorted-maps) to >> be equal if the associations are the same. Ditto for hash-sets and >> sorted-sets. >> >> >> This comes in handy once you realize that the core functions will sometimes return different types than you expected:
user=> (type (range 4)) clojure.lang.LazySeq user=> (reduce conj clojure.lang.PersistentQueue/EMPTY [0 1 2 3]) #<PersistentQueue clojure.lang.PersistentQueue@e44e33f5> user=> (type '(0 1 2 3)) clojure.lang.PersistentList user=> (type (subvec [0 1 2 3 4 5] 0 4)) clojure.lang.APersistentVector$SubVector user=> (type (vals {1 1 2 2 3 3 4 4})) clojure.lang.APersistentMap$ValSeq Putting it all together: user => (= (reduce conj clojure.lang.PersistentQueue/EMPTY [0 1 2 3]) (range 4) '(0 1 2 3) (subvec [0 1 2 3 4 5] 0 4) (vals {0 0 1 1 2 2 3 3})) true That right there is real power my friends. Timothy -- 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