# Default value of \*some\* fields in a mutable struct

**URL:** <https://discourse.julialang.org/t/default-value-of-some-fields-in-a-mutable-struct/33408>\
**Category:** General Usage\
**Tags:** struct\
**Created:** [January 15, 2020, 5:31pm UTC](https://discourse.julialang.org/t/default-value-of-some-fields-in-a-mutable-struct/33408 "2020-01-15T17:31:51Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [January 16, 2020, 12:50pm UTC](https://discourse.julialang.org/t/default-value-of-some-fields-in-a-mutable-struct/33408/18 "2020-01-16T12:50:34Z")

</div>

> [@davidbp](#):
>
> **Now I am only missing how to do this for any subset of the fields without specifying the values of the complementary part of the fields. Any ideas?**.

Are you looking for something like this?

```julia
mutable struct coly_xy
    x :: Int32
    y :: Float64
    z :: Bool
    t :: Int32
    u :: Float32
    v :: Bool
    function coly_xy(;kwargs...)
        K = new()
        for (key, value) in kwargs
            setfield!(K, key, value)
        end
        return K
    end
end

```

It allows you to specify the fields you want to set by name.

```julia
julia> coly_xy(t=Int32(13), v=true)
coly_xy(1, 1.0e-323, false, 13, 3.9061288f-19, true)

```

For more convenience you may want to add a `convert` call if the type doesn’t match.

---

_[View the full topic](https://discourse.julialang.org/t/default-value-of-some-fields-in-a-mutable-struct/33408)._
