You missed this:
http://docs.julialang.org/en/latest/manual/variables-and-scoping/#constants
However, it is not very clear, in particular concerning constant type vs
constant value. So an update would be good. Also, does it belong into the
scope-section?
On Wednesday, July 9, 2014 4:34:10 AM UTC+1, Leah Hanson wrote:
>
> The only reference I can find in the manual to the `const` keyword is in
> the performance section [1]. Well, that and the `isconst` function[2].
>
> This seems like it would be worth documenting, especially since it behaves
> significantly differently than the const that I remember from Java or C++,
> which prevented you from changing the value of const variable.
>
> I think I understand now, that `const` in Julia means that the type of the
> variable must remain constant. This was very surprising to me.
>
> ~~~.jl
> julia> const x = 10
> 10
>
> julia> x += 1
> Warning: redefining constant x
> 11
>
> julia> x
> 11
>
> julia> const arr = Int[1,2,3]
> 3-element Array{Int64,1}:
> 1
> 2
> 3
>
> julia> arr[1] = 13
> 13
>
> julia> arr
> 3-element Array{Int64,1}:
> 13
> 2
> 3
>
> julia> x += 0.5
> ERROR: invalid redefinition of constant x
> ~~~
>
> I'd be happy to add this to the manual, but I'm not sure where it belongs.
> Any suggestions?
>
>
> 1:
> http://docs.julialang.org/en/latest/manual/performance-tips/?highlight=const#avoid-global-variables
> 2:
> http://docs.julialang.org/en/latest/stdlib/base/?highlight=const#Base.isconst
>