Suppose I have some big struct and I also have some big dictionary. I want an element in the dictionary to “point to” a field of the struct, such that if I assign to the field of the struct, you’d “see it” by accessing the dictionary, and conversely, if I assign to the element in the dictionary, you’d “see it” in the struct. In C, I’d make the “dictionary” be a pointer to the field, and I could always write to the referenced location. How would this be done cleanly in Julia?
mutable struct MyStruct visible hidden end # Let's create a bunch of things that have both visible and hidden parts. s = MyStruct(1, 2) # Let's make a dictionary of visible things. d = Dict("entry1" => nothing, "entry2" => s.visible) s.visible = 3 display(d["entry2"]) # I'd like to see 3. d["entry2"] = 4 display(s.visible) # I'd like to see 4.
I could do something cheesy, like make the
visible field into a vector with 1 element and write to that, but I don’t like that solution at all.
I’m not sure if this actually involves
pointer). I’m just curious what the right approach is here. It seems like a basic thing to do.