Re: Detecting a byte array -- byte[]

2010-10-24 Thread Meikel Brandmeyer
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

Re: Detecting a byte array -- byte[]

2010-10-24 Thread Shantanu Kumar
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

Re: Detecting a byte array -- byte[]

2010-10-24 Thread Meikel Brandmeyer
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 --

Re: Detecting a byte array -- byte[]

2010-10-24 Thread Meikel Brandmeyer
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

Re: Detecting a byte array -- byte[]

2010-10-23 Thread Dave Ray
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

Detecting a byte array -- byte[]

2010-10-23 Thread Shantanu Kumar
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