Usage of keyword `const` in the context of types. (code from Julia documentation)

Hi, I read this in Julia doc (Types · The Julia Language)

julia> const T1 = Array{Array{T,1} where T, 1}
Array{Array{T,1} where T,1}
  1. What is the meaning of const in this context?
    • eg I built a variable like here below, and it is not very constant?
julia> aa=T1([[2.0],[6::Int64],["bof"]])
3-element Array{Array{T,1} where T,1}:
 [2.0]
 [6]
 ["bof"]
julia> aa[2]=[1];

julia> aa
3-element Array{Array{T,1} where T,1}:
 [2.0]
 [1]
 ["bof"]

I also tried this (without the const) like this: T2 = Array{Array{T,1} where T, 1} the difference with T1 is not clear to me.

  1. Where is the documentation for this use of const (ie in a type declaration context)?

Thank you!

const does not have any special meaning here.

This is not a “type declaring syntax” and merely an assignment of a type to a constant variable. In another word, the only difference between T1 and T2 is that you can assign to T2 but not to T1

1 Like

To build on yuyichao reply.
You basically renamed that particular type with T1, and reserved the name T1 for that particular use.

you declared T1 to be const, not aa, that is why you can manipulate the entries of aa.

1 Like

Thank you both!

There’s nothing you can do by adding const to make aa immutable.