I actually mentioned the cycle function in my message, and that's what
I was using, but the original question came up because accessing the
nth item in a list takes linear rather than constant time.

I'd be interested to hear how what I was attempting violates the
spirit of clojure. I was trying to work within the bounds of an
existing abstraction, and to implement my changes in such a way as to
not break other things that consume that abstraction.

Incidentally, I don't believe the error I'm getting from proxy has
anything to do with IPersistentVector being an interface, since you
can clearly do:

(proxy [clojure.lang.IFn] [])

and that works fine (although obviously is not related to solving my
particular problem).

On Mar 8, 5:20 pm, Timothy Pratley <timothyprat...@gmail.com> wrote:
> For your eueler problem consider using lazy functions cycle and range:
> user=> (take 15 (cycle (range 5)))
> (0 1 2 3 4 0 1 2 3 4 0 1 2 3 4)
> Or is there some other behavior you need to create?
>
> Regarding proxy your main problem is that IPersistentVector is an
> Interface (no implementation) so you would have to specify every
> method. More sensibly you could proxy the concrete implementation
> PersistentVector, however it does not have an empty constructor so you
> would need to figure out exactly what you want to do.
> user=> (proxy [clojure.lang.PersistentVector] [])
> java.lang.IllegalArgumentException: No matching ctor found for class
> clojure.proxy.clojure.lang.PersistentVector
>
> I would advise against proxying for this problem as it is complex and
> not in the spirit of solving the problem in Clojure.
>
> Regards.
> Tim.
>
> On Mar 9, 9:13 am, Paul  Mooser <taron...@gmail.com> wrote:
>
>
>
> > I was playing around with some project euler problems, and I was
> > thinking that the cycle function has an analog for vectors. I
> > implemented a short simple method with the right behavior (at a simple
> > surface level):
>
> > (defn cyclic-vector [v]
> >   (fn [x]
> >     (v (mod x (count v)))))
>
> > However, this obviously does not implement IPersistentVector.
>
> > Is there any easy way to implement something like this, and delegate
> > the rest of the behaviors to the base vector object ? I realize this
> > is probably possible with proxy, but I have not successfully made it
> > work yet - proxying the IPersistentVector interface results in the
> > following for me:
>
> > (proxy [clojure.lang.IPersistentVector] [])
>
> > java.lang.ClassFormatError: Duplicate method name&signature in class
> > file clojure/proxy/java/lang/Object$IPersistentVector (NO_SOURCE_FILE:
> > 2)
>
> > Is this an issue with proxy, or am I using it incorrectly ? I removed
> > any extraneous code of my own, since the error occurs with just the
> > minimal proxy usage shown above. I'm on trunk, revision 1326.
--~--~---------~--~----~------------~-------~--~----~
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