You can define our own datatype to do this. It's one of the most 
fundamental tasks in Julia!

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

Cédric

On Saturday, February 6, 2016 at 7:08:03 PM UTC-5, Ferran Mazzanti wrote:
>
> Hi folks,
>
> 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.
>
>

Reply via email to