wubbie,

In case you're asking because you're trying to test for collection-
like objects, there are (at least) two ways to do so:

1. coll? tests if its arg implements IPersistentCollection, i.e. is
one of the native Clojure persistent collections:

  user=> (map coll? [{} [] '() #{}])
  (true true true true)

2. the (if (seq coll) ...) idiom (you'll see a lot of it in
clojure.core) tests if the coll arg is seq-able, i.e. can be viewed as
a seq as Steve says above. This test will match for more than just the
Clojure collections, e.g.

  user=> (if (seq "hello") true false)
  true
  user=> (if (seq (into-array Character/TYPE [\a \b \c])) true false)
  true
  user=> (if (seq (doto (java.util.HashMap.) (.put "key" "val"))) true
false)
  true

Since seq is lazy, simply calling seq realizes no elements from the
seq-able thing.

Note, however, that seq will throw an error if given a non-seq-able
item like an integer (this is because the (if (seq coll) ...) test
involves actually calling seq on the arg...). Which means that it's
only safe for contexts in which you know the arg will be seq-able or
empty.

Best,
Perry
--~--~---------~--~----~------------~-------~--~----~
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
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