That requires dealing with an error and having a try/catch and it is just a pain. As I mentioned before, testing if the function `module_info/0` exists I think is a great way: ```elixir iex(9)> :erlang.function_exported(:blah, :module_info, 0) false iex(10)> :erlang.function_exported(String, :module_info, 0) true ```
On Thursday, July 21, 2016 at 12:14:30 PM UTC-6, Theron Boerner wrote: > > Use this: > > iex(7)> :erlang.get_module_info(String, :module) > String > iex(8)> :erlang.get_module_info(:lists, :module) > :lists > iex(9)> :erlang.get_module_info(:walrus, :module) > ** (ArgumentError) argument error > :erlang.get_module_info(:walrus, :module) > > > > On Thursday, July 21, 2016 at 12:20:46 PM UTC-5, ...Paul wrote: >> >> Not saying this is a great idea, but I'm working with a pattern where a >> parameter can be a module or a string. The gist is: >> >> def do_it(data, foo) when is_bitstring(foo), do: data >> def do_it(data, foo) do >> foo.do_other_thing(data) >> end >> >> Works great, but what if I want to allow actual atoms to be used, similar >> to strings? How can I identify the difference between an actual atom, like >> :bar, and a module, like Bar? >> >> is_atom() returns true for both cases (makes sense because module names >> are basically atoms, :"Elixir.Bar") Is there a way to tell the difference >> with a guard? >> >> If not a guard, some Kernel or Module function? >> >> ...Paul >> >> >> -- You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-talk+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/9fed8269-f58f-4d65-b369-ea6477b2126a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.