On Fri, Jul 3, 2015 at 9:29 AM, Ali Rezaee <arv.ka...@gmail.com> wrote:
> Hi,
>
> I have the following code:
>
> using DataStrucures
> d= DefaultDict(ASCIIString,Array{Int64},Array{Int64}(0))
>
> push!(d["A"],2)
> push!(d["B"],3)
>
> d
> DataStructures.DefaultDict{ASCIIString,Array{Int64,N},Array{Int64,1}} with 2
> entries:
>   "B" => [2,3]
>   "A" => [2,3]
>
>
> Isn't it unexpected that when I push to any key, the value is pushed to all
> the other keys as well?

Yes, pretty much. Because the default value is stored by reference and
you are mutating it with `push!`

See the last paragraph of the corresponding section in the
DataStructures.jl README[1]

[1] 
https://github.com/JuliaLang/DataStructures.jl#defaultdict-and-defaultordereddict

>
> Thanks :)

Reply via email to