Thinking more about this.
Would it be more useful for fill() and fill!() to take copies of mutable
objects? I can't really see a use case for fill that fills an array with
pointers to the same object.
Ivar
kl. 12:29:20 UTC+2 fredag 25. april 2014 skrev Ivar Nesje følgende:
>
> You can use a list comprehension, so that you actually create 16
> dictionaries.
>
> my_array_of_dicts = [Dict() for i = 1:4 , y = 1:4]
>
> Ivar
>
> kl. 12:24:22 UTC+2 fredag 25. april 2014 skrev joanenric barcelo følgende:
>>
>> Hello!
>> I want to create a multidimensional array of dicts, say 4x4. My first
>> guess was to use the function fill()
>> julia> my_array_of_dicts = fill(Dict(), 4, 4)
>>
>>
>> I want to include a new element to one of the dicts, say in position 2,2.
>> So
>> julia> my_array_of_dicts[2,2]["somekey"] = ["somevalue"]
>>
>> but what I get is
>>
>> julia> my_array_of_dicts
>> 4x4 Array{Dict{Any, Any}, 2}:
>> {"somekey"=>"somevalue"} . {"somekey"=>"somevalue"}
>> {"somekey"=>"somevalue"} . {"somekey"=>"somevalue"}
>>
>> {"somekey"=>"somevalue"} . {"somekey"=>"somevalue"}
>>
>> {"somekey"=>"somevalue"} . {"somekey"=>"somevalue"}
>>
>> so, basically the reference of every element of the array points to the
>> same object and all of the positions of the matrix are modified. Is there
>> any more suitable way to initialize a matrix of arrays without having this
>> problem?
>>
>>
>>
>>
>>
>