2
votes

Pretty simple question, I noted it when worked on exfile library.

This expression returns:

is_atom(nil) # => true

It's kinda unpredictable. My question is: how it's happened? Why it returns true?

2

2 Answers

8
votes

nil is an atom, along with true and false.

This is documented for true and false in http://elixir-lang.org/getting-started/basic-types.html#atoms

You can also check with:

nil == :nil
true == :true
false == :false

Some relevant links:

https://github.com/elixir-lang/elixir/blob/v1.3.2/lib/elixir/src/elixir_tokenizer.erl#L986 https://github.com/elixir-lang/elixir/blob/v1.3.2/lib/elixir/src/elixir_parser.yrl#L253

0
votes

Well, it is because "nil" is an atom, just like "true" or "false".