1defmodule Atom do
2  @moduledoc """
3  Atoms are constants whose values are their own name.
4
5  They are often useful to enumerate over distinct values, such as:
6
7      iex> :apple
8      :apple
9      iex> :orange
10      :orange
11      iex> :watermelon
12      :watermelon
13
14  Atoms are equal if their names are equal.
15
16      iex> :apple == :apple
17      true
18      iex> :apple == :orange
19      false
20
21  Often they are used to express the state of an operation, by using
22  values such as `:ok` and `:error`.
23
24  The booleans `true` and `false` are also atoms:
25
26      iex> true == :true
27      true
28      iex> is_atom(false)
29      true
30      iex> is_boolean(:false)
31      true
32
33  Elixir allows you to skip the leading `:` for the atoms `false`, `true`,
34  and `nil`.
35
36  Atoms must be composed of Unicode characters such as letters, numbers,
37  underscore, and `@`. If the keyword has a character that does not
38  belong to the category above, such as spaces, you can wrap it in
39  quotes:
40
41      iex> :"this is an atom with spaces"
42      :"this is an atom with spaces"
43
44  """
45
46  @doc """
47  Converts an atom to a string.
48
49  Inlined by the compiler.
50
51  ## Examples
52
53      iex> Atom.to_string(:foo)
54      "foo"
55
56  """
57  @spec to_string(atom) :: String.t()
58  def to_string(atom) do
59    :erlang.atom_to_binary(atom, :utf8)
60  end
61
62  @doc """
63  Converts an atom to a charlist.
64
65  Inlined by the compiler.
66
67  ## Examples
68
69      iex> Atom.to_charlist(:"An atom")
70      'An atom'
71
72  """
73  @spec to_charlist(atom) :: charlist
74  def to_charlist(atom) do
75    :erlang.atom_to_list(atom)
76  end
77
78  @doc false
79  @deprecated "Use Atom.to_charlist/1 instead"
80  @spec to_char_list(atom) :: charlist
81  def to_char_list(atom), do: Atom.to_charlist(atom)
82end
83