{"id":10974,"date":"2024-07-15T18:07:07","date_gmt":"2024-07-15T18:07:07","guid":{"rendered":"https:\/\/putridparrot.com\/blog\/?p=10974"},"modified":"2024-07-15T18:07:07","modified_gmt":"2024-07-15T18:07:07","slug":"elixir-atoms","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/elixir-atoms\/","title":{"rendered":"Elixir Atoms"},"content":{"rendered":"<p>One of the stranger bits of syntax I see in Elixir is for <a href=\"https:\/\/hexdocs.pm\/elixir\/1.12\/Atom.html\" rel=\"noopener\" target=\"_blank\">Atoms<\/a>.<\/p>\n<p>To quote the previous link &#8220;Atoms are constants whose values are their own name&#8221;. <\/p>\n<p>What does this mean ?<\/p>\n<p>Well imagine you were writing code such as<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nconfiguarion = &quot;configuration&quot;\r\nok = &quot;ok&quot;\r\n<\/pre>\n<p>Essentially the value is the same as the name, so basically instead if assigning a value of the same name we simply prefix the name with : to get the following<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n:configuration\r\n:ok\r\n<\/pre>\n<p>In fact :true, :false and :nil are atoms but we would tend to use the alias of these, i.e. without the colon, true, false and nil.<\/p>\n<p>The syntax for atoms is that they start with an alpha or underscore, can contain alphanumeric characters, can also contain @ and can end with and alphanumeric character or either ? or !. If you wish to create an atom with violates this syntax you can simply enclose in double quotes, i.e.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n:&quot;123atom&quot;\r\n<\/pre>\n<p>and to prove it we can use<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nis_atom(:&quot;123atom&quot;)\r\n<\/pre>\n<p>Atoms can also be declared starting with an uppercase alpha character such as<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nAtom\r\nis_atom(Atom)\r\n<\/pre>\n<p>Atoms with the same content are always equivalent.<\/p>\n<p>Modules are represented as atoms, for example :math is the module math and :&#8221;Elixir.String&#8221; is the same as a String.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the stranger bits of syntax I see in Elixir is for Atoms. To quote the previous link &#8220;Atoms are constants whose values are their own name&#8221;. What does this mean ? Well imagine you were writing code such as configuarion = &quot;configuration&quot; ok = &quot;ok&quot; Essentially the value is the same as the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[730],"tags":[],"class_list":["post-10974","post","type-post","status-publish","format-standard","hentry","category-elixir"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/10974","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=10974"}],"version-history":[{"count":5,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/10974\/revisions"}],"predecessor-version":[{"id":10979,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/10974\/revisions\/10979"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=10974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=10974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=10974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}