檢視原始碼 Atom (Elixir v1.16.2)

Atom 是常數,其值為其本身的名稱。

它們通常用於列舉不同的值,例如

iex> :apple
:apple
iex> :orange
:orange
iex> :watermelon
:watermelon

如果 Atom 的名稱相同,則它們相等。

iex> :apple == :apple
true
iex> :apple == :orange
false

它們通常用於表達操作的狀態,方法是使用 :ok:error 等值。

布林值 truefalse 也是 Atom

iex> true == :true
true
iex> is_atom(false)
true
iex> is_boolean(:false)
true

Elixir 允許您跳過 Atom falsetruenil 的前導 :

Atom 必須由 Unicode 字元組成,例如字母、數字、底線和 @。如果關鍵字具有不屬於上述類別的字元,例如空格,您可以用引號將其包起來

iex> :"this is an atom with spaces"
:"this is an atom with spaces"

摘要

函式

將 Atom 轉換為 charlist。

將 Atom 轉換為字串。

函式

@spec to_charlist(atom()) :: charlist()

將 Atom 轉換為 charlist。

由編譯器內嵌。

範例

iex> Atom.to_charlist(:"An atom")
'An atom'
@spec to_string(atom()) :: String.t()

將 Atom 轉換為字串。

由編譯器內嵌。

範例

iex> Atom.to_string(:foo)
"foo"