# How to make fields in type object undefined

**URL:** <https://discourse.julialang.org/t/how-to-make-fields-in-type-object-undefined/3082>\
**Category:** General Usage\
**Created:** [April 6, 2017, 7:49am UTC](https://discourse.julialang.org/t/how-to-make-fields-in-type-object-undefined/3082 "2017-04-06T07:49:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mazzanti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mazzanti/32/32948_2.png) [@mazzanti](https://discourse.julialang.org/u/mazzanti)\
**Post date:** [April 6, 2017, 7:49am UTC](https://discourse.julialang.org/t/how-to-make-fields-in-type-object-undefined/3082/1 "2017-04-06T07:49:49Z")

</div>

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

```julia
type fooo
    x :: Int
    y :: Float64
    z :: Int
    t :: Float64
    fooo() = new()
end;

```

and then

```julia
kkk = fooo()
kkk.x = 10
kkk

```

gives as result

> fooo(10,6.90533903150177e-310,139765626155696,6.90534204103743e-310)

while, obviously

```julia
isdefined(kkk,:x)

```

yields

> true

but

```julia
isdefined(kkk,:y)

```

also yields

> true

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,

Ferran.

---

<div class="post-metadata">

**Author:** ![merl-dev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/merl-dev/32/96_2.png) [@merl-dev](https://discourse.julialang.org/u/merl-dev)\
**Post date:** [April 6, 2017, 8:50am UTC](https://discourse.julialang.org/t/how-to-make-fields-in-type-object-undefined/3082/2 "2017-04-06T08:50:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [April 6, 2017, 10:41am UTC](https://discourse.julialang.org/t/how-to-make-fields-in-type-object-undefined/3082/3 "2017-04-06T10:41:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 6, 2017, 10:54am UTC](https://discourse.julialang.org/t/how-to-make-fields-in-type-object-undefined/3082/4 "2017-04-06T10:54:44Z")

</div>

> [@mazzanti](#):
>
> 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?

Not for [primitive types](http://docs.julialang.org/en/latest/manual/types.html#Primitive-Types-1). 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.
