How to find all atom exits in the system?

I want to create a module in runtime, when I donot need it, delete it from system.
But the module name must be an atom, so I want to know what is the best way,
to get an atom that is exist in system, but it’s not the name of any module.

For an atom, say :m, if it is a module, then :m.module_info() return a keyword, but if it is not a module,
it will raise a error. I think use this way, I can know if an atom is a pure atom, or it is alos a module’s name.

If you’re able to select an arbitrary atom :m and check if it’s already defined as a module alias, why can’t you pick a unique module name ahead of time MyApp.DynamicModule and avoid the error handling logic altogether?

1 Like

Yes, this is a good option. I will try it.
And thanks.

1 Like

For the record you can use this trick to list all existing atoms.

for i <- 0..:erlang.system_info(:atom_count)-1, do: :erlang.binary_to_term(<<131,75,i::24>>)



Thank you very much!

1 Like

While this is cool and impressive I’d love to see an official API for it one day.