Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Elixir's module an atom?

Tags:

erlang

elixir

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?

like image 627
Krzysztof Wende Avatar asked Apr 16 '15 12:04

Krzysztof Wende


People also ask

What is an atom in Erlang?

Atom is a special string-like data-type that is most commonly used for interfacing with code written in other BEAM languages such as Erlang and Elixir. It is preferable to define your own custom types to use instead of atoms where possible.

What is __ module __ In Elixir?

__MODULE__ is a compilation environment macros which is the current module name as an atom.


1 Answers

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.

like image 180
Ramon Snir Avatar answered Oct 08 '22 05:10

Ramon Snir