That’s a somewhat unorthodox approach, but it’s possible:
# Will raise if there's an attempt to use a number
# that doesn't have a corresponding module
mod = String.to_existing_atom("Elixir.Foo.Module_#{num}")
# Just call afterwards
mod.get()
The use of the String.to_existing_atom/1 is necessary because string to atom conversion isn’t safe in Erlang/Elixir, as atoms are not garbage collected, and filling up the atoms table is one of the ways to bring down the BEAM. Since the modules should be defined in the first place, the atoms that reference their names will already exist.
Hope it helps you ![]()


















