For reference, here's another vector implementation: https://github.com/clojure/clojure/blob/master/src/clj/clojure/gvec.clj
On Wed, Jul 10, 2013 at 6:39 PM, Cedric Greevey <cgree...@gmail.com> wrote: > If Clojure's code assumes IPersistentVectors to be Collections, why > doesn't IPersistentVector extend Collection? I'd consider that to be a bug. > > > On Wed, Jul 10, 2013 at 2:00 PM, Vincent <vhenneb...@gmail.com> wrote: > >> I guess I can proxy APersistentVector, but the Clojure docs [1] advise to >> use reify in favour to proxy whenever possible. My goal is to have my byte >> stream behave like a standard Clojure vector. (Parts of that stream also >> represent maps, and I'd like to do the same without loading them into >> Clojure maps, as they may be quite big.) It looks unidiomatic to me to >> resort to proxy to achieve that. Although maybe in the present case that's >> fine? >> >> I'm just remembering that Collection is an interface and not a class, so >> I guess that's not too bad since I can add it to my reify. >> >> [1] http://clojure.org/datatypes >> >> Thanks, >> Vincent >> >> >> >> On Tuesday, 9 July 2013 20:40:43 UTC+2, Gary Trakhman wrote: >> >>> From the lack of extending java's Collection in IPersistentVector or >>> associated interfaces, it seems like the intent is for every implementation >>> to extend (proxy) APersistentVector. Is that sufficient for what you're >>> trying to do? None of the methods in there are final. >>> >>> >>> On Tue, Jul 9, 2013 at 2:32 PM, Vincent <vhenn...@gmail.com> wrote: >>> >>>> Hello, >>>> >>>> Suppose I have a byte array representing an array of integers: >>>> $ clojure-repl >>>> Clojure 1.5.1 >>>> user=> (def v >>>> (let [a (byte-array (map byte [0 0 0 1 0 2 0 3]))] >>>> (reify clojure.lang.IPersistentVector >>>> clojure.lang.Seqable >>>> (seq [_] (for [i (range 0 (alength a) 2)] >>>> (bit-or (bit-shift-left (aget a i) 8) (aget a (inc >>>> i)))))))) >>>> #'user/v >>>> user=> (println v) >>>> [0 1 2 3] >>>> nil >>>> user=> (= [0 1 2 3] v) >>>> ClassCastException user$fn$reify__2 cannot be cast to >>>> java.util.Collection clojure.lang.**APersistentVector.doEquiv >>>> (APersistentVector.java:88) >>>> >>>> This is because doEquiv assumes that an instance of IPersistentVector >>>> also is an instance of Collection. While that may be true for standard >>>> Clojure data structures, this may not necessarily be the case for custom >>>> implementations. >>>> >>>> Am I really the first one to attempt something like that? Am I not >>>> supposed to write custom implementations of standard interfaces? Should >>>> that bug be raised in JIRA? >>>> >>>> Thanks, >>>> Vincent >>>> >>>> -- >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Clojure" group. >>>> To post to this group, send email to clo...@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+u...@**googlegroups.com >>>> >>>> For more options, visit this group at >>>> http://groups.google.com/**group/clojure?hl=en<http://groups.google.com/group/clojure?hl=en> >>>> --- >>>> You received this message because you are subscribed to the Google >>>> Groups "Clojure" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to clojure+u...@**googlegroups.com. >>>> >>>> For more options, visit >>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> >>>> . >>>> >>>> >>>> >>> >>> -- >> -- >> 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 >> --- >> You received this message because you are subscribed to the Google Groups >> "Clojure" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to clojure+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- > -- > 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 > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.