# Why can't I create an ImmutableDict from a vector of pairs (like for a normal cidt)

**URL:** <https://discourse.julialang.org/t/why-cant-i-create-an-immutabledict-from-a-vector-of-pairs-like-for-a-normal-cidt/107811>\
**Category:** General Usage\
**Created:** [December 19, 2023, 11:30am UTC](https://discourse.julialang.org/t/why-cant-i-create-an-immutabledict-from-a-vector-of-pairs-like-for-a-normal-cidt/107811 "2023-12-19T11:30:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [December 19, 2023, 11:30am UTC](https://discourse.julialang.org/t/why-cant-i-create-an-immutabledict-from-a-vector-of-pairs-like-for-a-normal-cidt/107811/1 "2023-12-19T11:30:25Z")

</div>

Minimal example:

```julia

pairs = [:A => 1, :B =>2]
d1 = Dict(pairs) # works
d2 = Base.ImmutableDict(pairs) # errors
d3 = Base.ImmutableDict(pairs...) # works

```

It seems strange that `d2` fails? Is there a reason, or a way to avoid splatting (I’ve been told to avoid this due to performance issues)?

---

<div class="post-metadata">

**Author:** ![gbaraldi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gbaraldi/32/22101_2.png) [@gbaraldi](https://discourse.julialang.org/u/gbaraldi)\
**Post date:** [December 19, 2023, 2:37pm UTC](https://discourse.julialang.org/t/why-cant-i-create-an-immutabledict-from-a-vector-of-pairs-like-for-a-normal-cidt/107811/2 "2023-12-19T14:37:49Z")

</div>

Maybe open an issue? ImmutableDict has mostly been used as an internal type and I guess nobody needed that function in base

---

<div class="post-metadata">

**Author:** ![mike.ingold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike.ingold/32/203749_2.png) [@mike.ingold](https://discourse.julialang.org/u/mike.ingold)\
**Post date:** [December 19, 2023, 3:05pm UTC](https://discourse.julialang.org/t/why-cant-i-create-an-immutabledict-from-a-vector-of-pairs-like-for-a-normal-cidt/107811/3 "2023-12-19T15:05:32Z")

</div>

Looks like the method for `Dict(::Vector{Pair})` comes from [here](https://github.com/JuliaLang/julia/blob/8e5136fa2979885081cd502d2210633dff1d2a1a/base/dict.jl#L80C1-L80C1) in the source. That function looks fairly generic, so I suspect it would work for most iterable types that generate `Pair`s. the `ImmutableDict` type is defined [here](https://github.com/JuliaLang/julia/blob/8e5136fa2979885081cd502d2210633dff1d2a1a/base/dict.jl#L759-L774), where there are definitely fewer methods defined.

It’s interesting that `ImmutableDict` is described in the docs ([here](https://docs.julialang.org/en/v1/base/collections/#Base.ImmutableDict)) but isn’t actually exported ([would be here](https://github.com/JuliaLang/julia/blob/8e5136fa2979885081cd502d2210633dff1d2a1a/base/exports.jl)). Not being exported often indicates that it’s an “internal” utility and not considered part of the API, so could be subject to breaking changes… but then why advertise it in the docs?

Edit: looks like this was previously noticed and commented on in [this Issue](https://github.com/JuliaLang/julia/issues/40413).

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [December 19, 2023, 3:25pm UTC](https://discourse.julialang.org/t/why-cant-i-create-an-immutabledict-from-a-vector-of-pairs-like-for-a-normal-cidt/107811/4 "2023-12-19T15:25:08Z")

</div>

Interesting to know. I am implementing metadata for an (internal) structure within Catalyst.jl. Since it is based on ModelingToolkit.jl, which uses ImmutableDict for its metadata, I decided to also go with it.
