# Extendable collection with immutable values

**URL:** https://discourse.julialang.org/t/extendable-collection-with-immutable-values/115869
**Category:** General Usage
**Created:** [June 19, 2024, 2:49pm UTC](https://discourse.julialang.org/t/extendable-collection-with-immutable-values/115869 "2024-06-19T14:49:38Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Deduction42](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/deduction42/32/9206_2.png) [@Deduction42](https://discourse.julialang.org/u/Deduction42)
#### Post date: [June 19, 2024, 2:49pm UTC](https://discourse.julialang.org/t/extendable-collection-with-immutable-values/115869/1 "2024-06-19T14:49:38Z")

</div>

I’m trying to build an efficient registry of certain values, and in this case, they’re all of the same type. I’m trying to find a good candidate “object” that fits this role. The desired properties are as follows:

1. Once a value in this registry is defined, it doesn’t change, so constant propagation should be possible at compile time
2. The registry needs to be extendable (at least once, preferably a handful of times) at the top-level script
3. Values can be referenced by symbols with valid variable names

The only thing that I can think of that has these properties is a

1. Module of constants that that you simply refer through getproperty, and inserts them with “eval”. This seems like overkill.
2. A zero-argument function `registry()` that returns an `ImmutableDict`, where `registry()` can be overwritten by a function `extend_registry(addreg)` through `@eval registry() = $newreg`. This should recompile any functions that use `registry()` and allow for constant propagation so that lookups only happen once.

Is there anything better available?

---

<div class="post-metadata">

### Author: ![Deduction42](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/deduction42/32/9206_2.png) [@Deduction42](https://discourse.julialang.org/u/Deduction42)
#### Post date: [June 19, 2024, 5:07pm UTC](https://discourse.julialang.org/t/extendable-collection-with-immutable-values/115869/2 "2024-06-19T17:07:43Z")

</div>

Also, this registry would probably contain a couple hundred entries. So maybe a module is the way to go here? Or even a LabelledArray @ChrisRackauckas? Ideally if the entry is inlined in the code I just want to do a lookup once at compile time and keep the result as a constant.

---

<div class="post-metadata">

### Author: ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)
#### Post date: [June 19, 2024, 5:56pm UTC](https://discourse.julialang.org/t/extendable-collection-with-immutable-values/115869/3 "2024-06-19T17:56:07Z")

</div>

Why not just put a named tuple into the type domain? E.g., `Val((; a = 3, b = 7))`.
