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:
- Once a value in this registry is defined, it doesn’t change, so constant propagation should be possible at compile time
- The registry needs to be extendable (at least once, preferably a handful of times) at the top-level script
- Values can be referenced by symbols with valid variable names
The only thing that I can think of that has these properties is a
- Module of constants that that you simply refer through getproperty, and inserts them with “eval”. This seems like overkill.
- A zero-argument function
registry()
that returns anImmutableDict
, whereregistry()
can be overwritten by a functionextend_registry(addreg)
through@eval registry() = $newreg
. This should recompile any functions that useregistry()
and allow for constant propagation so that lookups only happen once.
Is there anything better available?