Interesting question. Perhaps an example like this:
julia> const x = 10
10
julia> x = 11
Warning: redefining constant x
11
julia> x = 11.0
ERROR: invalid redefinition of constant x
could come fairly early (maybe in "Variables"). I'd say mention of the array
behavior could come in "Multi-dimensional Arrays".
The same issue applies to Dicts, and we don't really talk about them in the
main manual at all.
--Tim
On Tuesday, July 08, 2014 10:33:48 PM 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.iscons
> t