Also, unless you specifically want to support bitstrings (non-aligned binaries), then you probably want your guard to be `is_binary/1` instead of `is_bitstring/1`. :-)
On Thursday, July 21, 2016 at 11:26:53 AM UTC-6, OvermindDL1 wrote: > > Atoms and ModuleNames are one and the same, no difference, thus: > > There is no way to tell the difference between them without calling a > function on them (`module_info\1` is a good one since all modules have one, > could just test if the atom/module has that function), however this cannot > be done in a guard, so you'd have to test it in the body, then perhaps > delegate out to another function set. > > On Thursday, July 21, 2016 at 11:20:46 AM UTC-6, ...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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/7d8368eb-1fa9-45e8-8226-78fac3d081f6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
