Reputation: 53
I am trying to create a nested data structure in Julia using struct and Dict:
Struct
Int
String...
Dict
Basically, I want to be able to access/assign data in the form of
MyStruct.somedict["Boo"] = 2
Code:
struct Teststructwithdict
x::Int
y::Int
somedict::Dict{String,Int64}
end
aDict = Dict{String,Int64}("One" => 1, "Two" => 2, "Three" => 3)
aTeststructwithdict = Teststructwithdict(1,2,aDict)
function dicttestfunction(x::Teststructwithdict)
print(x)
end
dicttestfunction(aTeststructwithdict)
Error: Unfortunately, I am getting an error all the time. Not sure what is wrong here, or how I should proceed with error search.
invalid redefinition of constant Teststructwithdict
Stacktrace:
[1] top-level scope at none:0
Upvotes: 1
Views: 139
Reputation: 6086
The code you listed works without a problem, but if I change (redefine) Teststructwithdict it gives that error. Look for a redefinition of a struct in your code, or restart the Julia REPL session first if you need to define the struct again.
Upvotes: 3