# My ImmutableDict Changes Its Values

**URL:** <https://discourse.julialang.org/t/my-immutabledict-changes-its-values/81793>\
**Category:** General Usage\
**Tags:** question, debugging\
**Created:** [May 27, 2022, 3:31pm UTC](https://discourse.julialang.org/t/my-immutabledict-changes-its-values/81793 "2022-05-27T15:31:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dburch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dburch/32/8741_2.png) [@dburch](https://discourse.julialang.org/u/dburch)\
**Post date:** [May 27, 2022, 3:31pm UTC](https://discourse.julialang.org/t/my-immutabledict-changes-its-values/81793/1 "2022-05-27T15:31:57Z")

</div>

Is this correct? When I change some of the values in the last variable used to assign a key-val pair to the ImmutableDict the values in the immutable dictionary are changing. Is this a bug or correct behavior? Is so, then I guess I’ll try pushing NamedTuples into an array or something else.

My console output:

```julia
> julia> versioninfo()
> Julia Version 1.6.5
> Commit 9058264a69 (2021-12-19 12:30 UTC)
> Platform Info:
> OS: Windows (x86_64-w64-mingw32)
> CPU: Intel(R) Core(TM) i5-8365U CPU @ 1.60GHz
> WORD_SIZE: 64
> LIBM: libopenlibm
> LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
> Environment:
> JULIA_NUM_THREADS = 4
> 
> julia> include("c:/jl/test_immutable.jl")
> Everything is fine...
> 10.0 => Bool[0, 1, 1, 0, 0, 0, 1]
> 9.0 => Bool[1, 0, 1, 0, 0, 0, 1]
> 8.0 => Bool[1, 0, 1, 0, 0, 0, 0]
> But then we change the boolean values of yVals using an index...
> ...and now the last entry has changed
> 10.0 => Bool[0, 0, 0, 0, 0, 0, 1]
> 9.0 => Bool[1, 0, 1, 0, 0, 0, 1]
> 8.0 => Bool[1, 0, 1, 0, 0, 0, 0]
> Is this correct that the ImmutableDict can be changed in this way?

```

My MWE code:

```julia
ImmD = Base.ImmutableDict{Float64, Vector{Bool}}

xKey = 8.0
yVals = Bool[1,0,1,0,0,0,0]
ImmD = Base.ImmutableDict(xKey=>yVals)

xKey = 9.0
yVals = Bool[1,0,1,0,0,0,1]
ImmD = Base.ImmutableDict(ImmD, xKey=>yVals)

xKey = 10.0
yVals = Bool[0,1,1,0,0,0,1]
ImmD = Base.ImmutableDict(ImmD, xKey=>yVals)

println("Everything is fine...")
foreach(println, ImmD)

println("But then we change the boolean values of yVals using an index...")
yVals[2] = 0
yVals[3] = 0

println("...and now the last entry has changed")
foreach(println, ImmD)

println("Is this correct that the ImmutableDict can be changed in this way?")

```

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [May 27, 2022, 3:39pm UTC](https://discourse.julialang.org/t/my-immutabledict-changes-its-values/81793/2 "2022-05-27T15:39:23Z")

</div>

The Dict is immutable, not the values in it. Those are mutable arrays and you’ve mutated some of them.
