Question

I'm trying to make a constructor for a custom type in Julia:

type Cell
  Base::Dict{String, String}
  zLayers::Array{Dict{String, String},2}
  X::Int
  Y::Int

  Cell() = new(Dict{String,String}(),[Dict{String, String}(),Dict{String, String}()],0,0)
end

try
  gamestate = Cell()
catch err
  print("connection ended with error $err\n")
end

Throws error:

connection ended with error MethodError(convert,(Array{Dict{String,String},2},[Dict{String,String}(),Dict{String,String}()]))

So how do we do proper initialization for Arrays of Dictionaries?

Was it helpful?

Solution

This question was double posted and answered on the mailiglist.

https://groups.google.com/forum/m/#!topic/julia-users/zE8Ri8rbfHQ

I think you’re confusing the 2 in an Array parameter set with the number of items, when it’s the number of dimensions. I’m pretty sure you’re creating a Vector, not a Matrix.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top