I was wondering if it is possible to use in a simple way cyclic arrays in Julia? What I'm after is sometbing that understands that the next element in a[] after end is a[1], so a[end+1]=a[1], a[end+2]=a[2] etc... I know I can index the array with the remainder operator % to achieve this same result, but I wonder if one can declare the array directly in one way or another to achieve this directly.
Thanks in advance,
Ferran.
immutable CircularArray{T}
arr::Vector{T}
end
Base.getindex(ca::CircularArray, i) = ca.arr[(i-1) % length(ca.arr) + 1]
Base.setindex(...) = ...
...
a = CircularArray([1,2,3])
a[14] # yields 2