- Mastering Elixir
- André Albuquerque Daniel Caixinha
- 242字
- 2021-08-05 10:42:44
Atoms
Atoms are a constant, whose value is its own name. They are always prefixed with a leading colon (:), followed by alphanumeric characters (and possibly _ or @). They may terminate with an exclamation or a question mark. Atoms are similar to enumerations in C and symbols in Ruby. Here are some examples of atoms:
iex> :ok
:ok
iex> :error
:error
iex> :some_descriptive_name!
:some_descriptive_name!
iex> :value@start
:value@start
You can create atoms with arbitrary characters with the following syntax:
iex> :"Atom name with arbitrary characters#$%^"
:"Atom name with arbitrary characters#$%^"
As with all data structures in Elixir, atoms can't be modified after their creation. Furthermore, they are not garbage-collected. Atoms are kept in the atom table, and upon compilation, their value is replaced by a reference to their entry on this table. This makes comparing atoms very efficient. As you'll learn throughout this book, this is one of the major use cases for atoms in Elixir, as we are constantly matching the return of a function against a certain expected atom.
- AngularJS Testing Cookbook
- Building a Home Security System with Raspberry Pi
- Full-Stack Vue.js 2 and Laravel 5
- 手把手教你學(xué)C語言
- SQL基礎(chǔ)教程(第2版)
- Java實(shí)戰(zhàn)(第2版)
- PHP 7從零基礎(chǔ)到項(xiàng)目實(shí)戰(zhàn)
- 軟件體系結(jié)構(gòu)
- Android應(yīng)用開發(fā)實(shí)戰(zhàn)
- Building Business Websites with Squarespace 7(Second Edition)
- Instant GLEW
- Mastering OpenStack
- Developer,Advocate!
- Java Script從入門到精通(第5版)
- SAP HANA Starter