Can I alias an array element to a simple name like `x`?

I want to alias some array elements to simple variable names for readability:

a = collect(700:710)
alias b = a[10] # pseudocode
alias c = a[20]
b = 6
@assert a[10] == 6

How can I do this? The aliases can be only in the current scope so as not to introduce GC problems.

You can use single-element views:

julia> a = collect(700:710);

julia> b = @view a[10]
0-dimensional view(::Array{Int64,1}, 10) with eltype Int64:
709

julia> b .= 6
0-dimensional view(::Array{Int64,1}, 10) with eltype Int64:
6

julia> a[10]
6
4 Likes

b[] = 13 # assignment

Thanks.

1 Like