Recompiling functions with infrequently mutating constant

Ooooh! “eval” a programmatically generated expresion! Of course! Why didn’t I think of that?

function rename_indexer(names::NTuple{N, Symbol}) where N
    ex = :(build_indexer() = NamedTuple{Tuple($names)}(Tuple(1:$N)))
    eval(ex)
    return nothing
end

julia> rename_indexer((:one,:two,:three))
build_indexer (generic function with 1 method)

julia> build_indexer()
(one = 1, two = 2, three = 3)

julia> rename_indexer((:a,:b,:c))
build_indexer (generic function with 1 method)

julia> build_indexer()
(a = 1, b = 2, c = 3)

This solution is WAAAY simpler and only a LITTLE bit hacky. I don’t even need the global variable anymore! Anyway, there’s may be a way for me to get around the indexer altogether, but this is a good thought exercise for me. At least I think I have a workable fallback if it turns out I can’t get around it.