18

I'm trying to get to know what modules are in Elixir. Because in Erlang they're just atoms, but in Elixir atoms start with : character. So I've checked these expressions in iex:

iex(16)> is_atom(List) 
true
iex(17)> is_atom(:List)
true
iex(18)> List == :List
false
iex(19)> a = List
List
iex(20)> b = :List
:List

So it's pretty clear that both List and :List are atoms. However, how does it work on Erlang interop layer? Because Erlang's ok is equal to Elixir's :ok.
So which one of these two (List and :List) is equal to 'List' in Erlang?

Simone
  • 20,302
  • 14
  • 79
  • 103
Krzysztof Wende
  • 3,208
  • 25
  • 38

1 Answers1

29
Interactive Elixir (1.0.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> List == :List
false
iex(2)> List == :'Elixir.List'
true

All uppercase atoms in Elixir automatically receive the Elixir. prefix.

Ramon Snir
  • 7,520
  • 3
  • 43
  • 61
  • 10
    Great answer! To be 100% precise in the naming, `List`, `String` in Elixir are called aliases and they expand to atoms. So `List` expands to the :"Elixir.List". However, you can make an alias point to whatever you want using the `alias` special form, for example: `alias :foo, as: List`. – José Valim Apr 16 '15 at 17:48
  • @JoséValim How can I achieve such alias from string than? `String.to_atom("List")` gives `:List`. I use `{atom, _} = Code.eval_string("List")` But I imagine it's not the safest way to do it – Krzysztof Wende Apr 17 '15 at 14:19
  • 5
    Check `Module.concat/2` and `Module.split/1`. – José Valim Apr 17 '15 at 20:15