# Mutating a mutable field of an immutable and exclamation mark

**URL:** https://discourse.julialang.org/t/mutating-a-mutable-field-of-an-immutable-and-exclamation-mark/21279
**Category:** New to Julia
**Tags:** question
**Created:** [February 27, 2019, 8:45pm UTC](https://discourse.julialang.org/t/mutating-a-mutable-field-of-an-immutable-and-exclamation-mark/21279 "2019-02-27T20:45:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Pavel\_Kalouguine](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pavel_kalouguine/32/7730_2.png) [@Pavel\_Kalouguine](https://discourse.julialang.org/u/Pavel_Kalouguine)
#### Post date: [February 27, 2019, 8:45pm UTC](https://discourse.julialang.org/t/mutating-a-mutable-field-of-an-immutable-and-exclamation-mark/21279/1 "2019-02-27T20:45:31Z")

</div>

Should one decorate the name of the function that modifies a mutable field of an immutable structure with an exclamation mark? For instance, should one call the function in the example below “optimize!” or “optimize”?

```julia
struct SomeData
    x::Int
end

struct Augmentation
    y::Vector{Int}
end

Augmentation()=Augmentation([0])

struct AugmentedData
    s::SomeData
    a::Augmentation
end

AugmentedData(s::SomeData)=AugmentedData(s, Augmentation())

function optimize!(ad::AugmentedData)
    ad.a.y[1]=42
    nothing
end

julia> ad=AugmentedData(s)
AugmentedData(SomeData(1), Augmentation([0]))
julia> optimize!(ad)
julia> ad
AugmentedData(SomeData(1), Augmentation([42]))

```

---

<div class="post-metadata">

### Author: ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)
#### Post date: [February 27, 2019, 8:46pm UTC](https://discourse.julialang.org/t/mutating-a-mutable-field-of-an-immutable-and-exclamation-mark/21279/2 "2019-02-27T20:46:36Z")

</div>

`optimize!`, because you are mutating the contents.

---

<div class="post-metadata">

### Author: ![Pavel\_Kalouguine](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pavel_kalouguine/32/7730_2.png) [@Pavel\_Kalouguine](https://discourse.julialang.org/u/Pavel_Kalouguine)
#### Post date: [February 27, 2019, 8:48pm UTC](https://discourse.julialang.org/t/mutating-a-mutable-field-of-an-immutable-and-exclamation-mark/21279/3 "2019-02-27T20:48:50Z")

</div>

This is what I think, too. But it looks a bit weird for a function taking a single immutable argument.
