How to make fields in type object undefined


Hi folks,
in many of my julia codes I define my own type variables, in such a way that nothing is by default initialized, expecting the user will initialize the fields he needs. For instance

type fooo
    x :: Int
    y :: Float64
    z :: Int
    t :: Float64
    fooo() = new()

and then

kkk = fooo()
kkk.x = 10

gives as result


while, obviously






also yields


because some values have been set to kkk.y. My question is: is there a way to get to know that kkk.x has been given a value while kkk.y contains garbage and has not been given any value by the user?

Best regards and thanks,



Nope. Consider changing your type fields to Nullables and then use isnull.


You can use a “sentinel value”, i.e. a special value that is not valid for your use case. For example, that could be -1 for integer fields if they must be non-negative, or NaN for Floats.


Not for primitive types. Think about it: since every bit pattern is a meaningful value, it is impossible to know how it got there.

As @dpsanders said, sentinel values are in general a possible solution, but if you tell us more about your problem, you might get a more specific suggestion.