- 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.
- HTML5+CSS3+JavaScript從入門到精通:上冊(微課精編版·第2版)
- INSTANT Mock Testing with PowerMock
- Java多線程編程實戰指南:設計模式篇(第2版)
- Python for Secret Agents:Volume II
- NumPy Essentials
- Full-Stack Vue.js 2 and Laravel 5
- Python高效開發實戰:Django、Tornado、Flask、Twisted(第3版)
- Python Web數據分析可視化:基于Django框架的開發實戰
- Windows內核編程
- 從零開始學C語言
- HTML5與CSS3基礎教程(第8版)
- Visual Basic程序設計上機實驗教程
- 詳解MATLAB圖形繪制技術
- Mockito Essentials
- Python Deep Learning