Hi,
On 24 Okt., 14:27, Shantanu Kumar wrote:
> by the way the Class/forName thing completely took me by
> surprise. :-)
Also useful for protocols (extend-type (Class/forName ...)) and
multimethods (defmethod foo (Class/forName ...)).
Sincerely
Meikel
--
You received this message because you
Thanks Dave and Meikel,
This is really useful. Maybe they should have been part of
clojure.core; by the way the Class/forName thing completely took me by
surprise. :-)
Regards,
Shantanu
On Oct 24, 4:07 pm, Meikel Brandmeyer wrote:
> Hi,
>
> On 24 Okt., 05:53, Shantanu Kumar wrote:
>
> > I want
Hi,
On 24 Okt., 05:53, Shantanu Kumar wrote:
> I want to be able to detect arrays of other types too - e.g.
> char[], Integer[] etc.
Other types can be done as "[C" (char), "[Ljava.lang.String;", etc.
You can get the types via type or class in the repl.
Hope this helps.
Sincerely
Meikel
--
Hi,
user=> (defn byte-array? [o] (instance? (Class/forName "[B") o))
#'user/byte-array?
user=> (byte-array? "abc")
false
user=> (byte-array? (byte-array [(byte 1) (byte 2)]))
true
Sincerely
Meikel
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To p
This should do it:
user=> (defn byte-array? [obj] (= Byte/TYPE (.getComponentType (class obj
#'user/byte-array?
user=> (byte-array? (byte-array [(byte 56) (byte 98)]))
true
user=> (byte-array? "")
false
user=> (byte-array? 99)
false
Hope that helps,
Dave
On Sat, Oct 23, 2010 at 11:53 PM, Sh
Hi
Can anybody tell me how can I detect that a given object is a byte
array? Or maybe show me how to write a (defn byte-array? [obj] ..)
function? I want to be able to detect arrays of other types too - e.g.
char[], Integer[] etc.
I experimented a bit at the REPL:
user=> (type (byte-array [(byte